所以我建立一个"找到你附近的安装程序"允许用户使用Page1上的邮政编码填写输入字段的功能。然后,当他们点击搜索时,会将其重定向到Page2,查找安装程序页面,并使用邮政编码填写搜索框。我已经完成了所有工作的邮政编码填写并通过网址将数据传输到新页面,但我无法设置一个.keyup事件成功触发一旦邮政编码设置为搜索框。密钥将导致结果刷新并使用户高兴地看到他们的结果。
这是我到目前为止的代码,我们将非常感谢任何帮助/建议!
修改:供参考我使用Flippercode开发的Wordpress Google Maps Pro插件。
// Grab the value when the user clicks the search button,
// and encode it in the url.
$(function () {
$("#zip-search").bind("click", function () {
var url = "../find-an-installer?zipField=" + encodeURIComponent($("#zip-field").val());
window.location.href = url;
});
});
// Decode the url and grab the value.
var queryString = new Array();
$(function () {
if (queryString.length == 0) {
if (window.location.search.split('?').length > 1) {
var params = window.location.search.split('?')[1].split('&');
for (var i = 0; i < params.length; i++) {
var key = params[i].split('=')[0];
var value = decodeURIComponent(params[i].split('=')[1]);
queryString[key] = value;
}
}
}
// Make sure the value is present, and set variables.
if (queryString["zipField"] != null) {
var data = "";
data += queryString["zipField"];
var userZip = data;
}
// Place the value in the search box
$(function fillValue() {
$(".wpgmp_search_input").val(userZip);
console.log("Fill value ran succesfully");
});
// Need to figure out how to trigger a keyup once the value is filled,
// so the search function fires and updates the results.
});
&#13;
答案 0 :(得分:1)
字面上,当我发布我的问题时,我终于明白了。虽然这可能不是最具语义性的,但我绝对愿意改进这个解决方案。
ffmpeg.sdp
答案 1 :(得分:1)
// Grab the value when the user clicks the search button,
// and encode it in the url.
$(function () {
$("#zip-search").bind("click", function () {
var url = "../find-an-installer?zipField=" + encodeURIComponent($("#zip-field").val());
window.location.href = url;
});
});
// Decode the url and grab the value.
var queryString = new Array();
$(function () {
if (queryString.length == 0) {
if (window.location.search.split('?').length > 1) {
var params = window.location.search.split('?')[1].split('&');
for (var i = 0; i < params.length; i++) {
var key = params[i].split('=')[0];
var value = decodeURIComponent(params[i].split('=')[1]);
queryString[key] = value;
}
}
}
// Make sure the value is present, and set variables.
if (queryString["zipField"] != null) {
var data = "";
data += queryString["zipField"];
var userZip = data;
}
// Place the value in the search box
$(function fillValue() {
//if a regular event
$(".wpgmp_search_input").val(userZip).keyup();
//if a custom function you've bind
$(".wpgmp_search_input").val(userZip).trigger("myCustomEvent:keyup");
console.log("Fill value ran succesfully");
});
});