异步加载时 jQuery livesearch 不工作
我有一个 livesearch,它使用一个无序列表,如下所示:
<input id="search"/>
<ul id="list>
<li>1</li>
<li>2</li>
</ul>
现在我将 liveSearch 功能放在这些项目上:
$('#search').liveUpdate('#list').focus();
起初我使用静态列表进行测试,它的工作方式就像魅力一样。 现在我尝试使用以下语句异步加载它:
//$('#list').load('/search/organization');
//$('#list').load('/search/person');
//$('#list').load('/search/debitor');
$('#list').load('/search/accountname');
数据已正常加载,但现在搜索不再工作。我不太习惯使用ajax,所以也许这是一个常见问题?
提前致谢,
编辑:
当我添加这一行代码或在其他地方提醒它时,它会返回 1。 ul 中始终只有一个元素。
$('#list').load('/search/organization');
var test = jQuery('#list');
alert(test.length);
仍然没有找到解决办法。
I have a livesearch and it uses an unordered list, like this:
<input id="search"/>
<ul id="list>
<li>1</li>
<li>2</li>
</ul>
Now I have the liveSearch function put on these items:
$('#search').liveUpdate('#list').focus();
At first I was testing with a static list, it worked like charm.
Now I'm trying to load it asynchronous with the following statements:
//$('#list').load('/search/organization');
//$('#list').load('/search/person');
//$('#list').load('/search/debitor');
$('#list').load('/search/accountname');
The data is loaded as normal but now the search isn't working anymore. I'm not that used to using ajax so maybe this is a common problem?
Thanks in advance,
EDIT:
When I add this line of code, or alert it somewhere else it returns 1. There is always only one element in the ul.
$('#list').load('/search/organization');
var test = jQuery('#list');
alert(test.length);
Still no sollution found.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该插件实际上有一个正在被替换的
元素的缓存,因此您需要“取消绑定”以前的处理程序并再次重新绑定它,如下所示
: “http://ejohn.org/blog/jquery-livesearch/” rel="nofollow noreferrer">该插件已安装到
.keyup()
处理程序,您只需取消绑定它并添加一个新的。要真正清理,您可以添加.parents('form').unbind('submit')
,但如果您有任何其他 在The plugin actually has a cache of the
<li>
elements that are being replaced, so you need to "unbind" the former handler and re-bind it again, like this:Since the plugin is rigged up to the
.keyup()
handler, you're just unbinding that and adding a new one. To really clean up, you could add a.parents('form').unbind('submit')
, but if you had any other submit handlers on the<form>
, that'd be a bad idea :)