jQuery 一键单击,两次操作。帮助!
我正在构建一个具有自动完成功能的 Intranet 站点。我让它工作到当用户单击自动完成列表中的名称时,它将将该值填充到文本输入框。我需要它做的是在填写值后,还提交表单,就像 Google 那样。我知道我必须使用 document.formname.submit
,但我无法让它同时执行这两项操作,我所能得到的只是其中之一。我通常会研究如何做到这一点,但我的日程很紧,真的需要你的帮助!这是到目前为止我所拥有的代码。
function suggest(a) {
if (a.length == 0) {
$("#suggestions").fadeOut()
} else {
$("#search").addClass("load");
$.post("autosuggest.php", {
queryString: "" + a + ""
},
function (b) {
if (b.length > 0) {
$("#suggestions").fadeIn();
$("#suggestionsList").html(b);
$("#search").removeClass("load")
}
})
}
}
function fill(a) {
$("#search").val(a);
setTimeout("$('#suggestions').fadeOut();", 300)
};
I'm building an intranet site for work with an autocomplete feature. I have it working to where when the user clicks on the name in the autocomplete list, it will fill that value to the text input box. What I need it to do is after it fills in the value, also submit the form, à la Google. I know I have to use document.formname.submit
, but I can't get it to do both, all I can get is one or the other. I would usually research how to do this, but I'm on a tight schedule and really need your help! Here's what I have for the code so far.
function suggest(a) {
if (a.length == 0) {
$("#suggestions").fadeOut()
} else {
$("#search").addClass("load");
$.post("autosuggest.php", {
queryString: "" + a + ""
},
function (b) {
if (b.length > 0) {
$("#suggestions").fadeIn();
$("#suggestionsList").html(b);
$("#search").removeClass("load")
}
})
}
}
function fill(a) {
$("#search").val(a);
setTimeout("$('#suggestions').fadeOut();", 300)
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
怎么样:
What about:
'submit' 是一个方法,所以你需要在它后面加上括号以便实际执行任何操作:
因为无论如何你都在使用 jQuery,所以你最好坚持使用事件内容如果你以后需要做更复杂的事情,它会更强大。
在这种情况下,您必须为表单提供一个 ID 属性(如果还没有)并使用:
'submit' is a method, so you'll be wanting to put brackets after it in order to actually do anything:
Since you're using jQuery anyway, you're better off sticking with the event stuff you get with that, it's much more powerful if you need to do more complicated things later on.
In this instance you'll have to give your form an ID attribute (if there isn't one already) and use:
您需要在 $.post 方法的回调处理程序中调用
document.formname.submit()
或$("#form-id").submit()
。这就是你现在正在做的事情吗?You need to call
document.formname.submit()
or$("#form-id").submit()
at the callback handler of the $.post method. Is that what you are doing now?