gpt4 book ai didi

javascript - jquery 的 "live"函数的问题

转载 作者:数据小太阳 更新时间:2023-10-29 05:16:47 25 4
gpt4 key购买 nike

问题

这很好用:

$('#edit_curriculum .generated').children().blur(function(){
console.log(this);
});

但这不是:

$('#edit_curriculum .generated').children().live('blur', function(){
console.log(this);
});

obs:函数包装在 $(document).ready 事件中。


输出

工作:

<input type=​"text" name=​"phones[]​" class=​"medium phone valid">

不工作:

Uncaught Syntax error, unrecognized expression: )
k.errorjquery.js:17
k.filterjquery.js:17
kjquery.js:17
c.querySelectorAll.kjquery.js:17
k.matchesSelectorjquery.js:17
f.extend.filterjquery.js:17
f.fn.extend.isjquery.js:17
f.fn.extend.closestjquery.js:17
Njquery.js:16
f.event.handlejquery.js:17
f.event.add.k.i.handle.kjquery.js:16
f.event.triggerjquery.js:17
ejquery.js:17

最佳答案

来自 jQuery live()文档:

Attach a handler to the event for all elements which match the current selector, now and in the future.

此函数适用于选择器,而不是元素集合。我会使用以下语法:

 $('#edit_curriculum .generated > *').live('blur', function(){
console.log(this);
});

此选择器将获得任何直接子项(因此您之前拥有的),但使用selection 而不是traversal。这应该允许您按预期使用 live()。希望这对您有所帮助!

关于javascript - jquery 的 "live"函数的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7059809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com