我需要您的帮助,我有一张带有提取位置字段的google map,第二个是提取字段,im试图做的是使用以下代码将值从我的首页传递到单个页面,因此当前字段打击是下车字段,我如何才能使其自动搜索使用javascript添加的值?我的第一个选择是尝试创建一个虚拟印刷机,您可以在下面检查该虚拟印刷机,但无法正常工作,下面的代码旨在帮助我单击字段下的箭头并输入搜索内容,而无需按任何键盘键,但它不起作用
HTML
<input type="text" name="location" class="location" id="destination-autocomplete" placeholder="Enter a location" autocomplete="off">
用于按键的JS
$("#showBooking").click(function(){
$('#destination-autocomplete').trigger(jQuery.Event('keypress', { keycode: 13 }));
$('#destination-autocomplete').trigger(jQuery.Event('keypress', { keycode: 40 }));
$('#destination-autocomplete').trigger(jQuery.Event('keypress', { keycode: 13 }));
});
$('#destination-autocomplete').keypress(function() {
console.log( "Handler for .keypress() called." );
});
JS用于通过Google输入将值从首页传递到单个页面
jQuery(document).ready(function($){
if(window.location.href.indexOf("/product/") > -1) {
var path = window.location.href;
//get all url parameters
var parameters = path.split("?")[1];
// get the parameters
var para1 = parameters.split("&")[0];
var para2 = parameters.split("&")[1];
var para3 = parameters.split("&")[2];
// get the parameter value
var para1var = para1.split("=")[1];
var para2var = para2.split("=")[1];
var para3var = para3.split("=")[1];
var strone = para1var;
var replacedd = strone.split('_').join(' ');
var strtwo = para2var;
var replacedtwo = strtwo.split('_').join(' ');
$('#destination-autocomplete').val(replacedd);
$('#pickup-destination-autocomplete').val(replacedtwo);
}
});