【发布时间】:2017-08-07 02:11:38
【问题描述】:
当 Ajax 在我的页面上完成运行时,我目前正在运行以下函数,然后加载文本(现在),然后打开自动完成对话框。
<script type="text/javascript"> $(document).ajaxComplete(function() {
jQuery('#facetwp-location').val('Richmond, Vic'); // populate the input box
google.maps.event.trigger( document.querySelector('#facetwp-location'), 'focus', {} ); // force the autocomplete to show
});
</script>
我需要做以下事情:
- 从 BuddyPress Xprofile 字段中获取用户位置信息(将替换预先编写的文本)
- 自动加载自动完成列表中的第一项(即模拟一个按键并在显示的列表上输入
再一次,我的jQuery技能欠缺,需要一些帮助才能完成这个功能。
我已经完成了,到目前为止已经完成了 - 但它仍然不完整
function get_user_location_for_facet_load(){
if (is_page(2101)) {
?>
<script type="text/javascript">
$(function() {
$(document).ajaxStop(function() {
jQuery('#facetwp-location').val('<?php
$user_id = bp_loggedin_user_id();
echo xprofile_get_field_data('Suburb',$user_id);
?>'); // populate the input box
$('#facetwp-location').focus();
google.maps.event.trigger( document.querySelector('#facetwp-location'), 'focus', {} ); // force the autocomplete to show
$( ".pac-container .pac-item:first" ).promise().done(function() {
google.maps.event.trigger( document.querySelector('.pac-container .pac-item'), 'focus', {} );
google.maps.event.trigger(document.querySelector('.pac-container .pac-item'), 'keydown', {
keyCode: 13
});
//var txt = $('#facetwp-location').val();
//alert(txt);
});
});
});
</script>
<?php
}
不确定我是否更接近,但是否有人可以提供帮助。
【问题讨论】:
标签: jquery wordpress google-maps-api-3 autocomplete buddypress