簡體   English   中英

jquery的“live”問題function

[英]problem with jquery's “live” function

問題

這工作正常:

$('#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()文檔:

將處理程序附加到與當前選擇器匹配的所有元素的事件,現在和將來。

此 function 旨在用於selector ,而不是元素集合。 我會使用以下語法:

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

此選擇器將獲得任何直接子代(因此您之前擁有的),但帶有selection而不是traversal 這應該允許您按預期使用live() 希望這可以幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM