$(document).delegate("input#search-champions", "change", function(e)
每当我更改search-champions
内的值时,我必须在文本框外部单击才能使其正常工作。我希望函数在文本框内的值发生变化时运行。
我忘记了它的名称,但它与Google用于搜索的系统相同。你写A,它会用A显示结果。
答案 0 :(得分:2)
尝试绑定到keyup
事件:
$(document).delegate("#search-champions", 'keyup', function(e)
顺便说一下,不需要在input
前面添加选择器 - 无论如何ID都应该是唯一的!
答案 1 :(得分:1)
更改事件对文本框不起作用。改为你可以使用按键或按键事件。 你想要什么我们称之为自动完成。 所以最好的方法是在keyup事件上
$(document).delegate("input#search-champions", "keyup", function(e){
var elm=$(this);
var str=elm.val();
//now you can get word starting from a either from some array or server call or ajax.
});
如果您使用的是jquery ui。它具有自动完成功能。
http://jqueryui.com/autocomplete/
$(document).delegate(“input#search-champions”,“change”,function(e)