【发布时间】:2015-09-03 18:33:56
【问题描述】:
因此,我正在构建一个“查找您附近的安装程序”功能,该功能允许用户在第 1 页上填写带有邮政编码的输入字段。然后,当他们单击搜索时,它会将他们重定向到 Page2,查找安装程序页面,并使用邮政编码填写搜索框。我已经完成了所有使用邮政编码的工作,并通过 url 将数据传输到新页面,但是一旦邮政编码设置为搜索框中的值,我无法成功触发 .keyup 事件. 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.
});
【问题讨论】:
-
在
textbox中设置值后只需调用$("#zip-search").click();
标签: javascript jquery wordpress events plugins