fek*_*lek 2 jquery jquery-selectors
我有这个问题与Jquery项[c]被很好地定义为HTMLElement但是当我使用.find与多个选择器时,我得到这个错误:
TypeError: X[g].exec is not a function
http://code.jquery.com/jquery-latest.min.js
Run Code Online (Sandbox Code Playgroud)
当我查看一些手表时,我得到了下图中的内容:
$(items[c]).find('.received') 工作正常并返回一些元素,因为有该类的元素
$(items[c]).find('.receive') 也可以正常工作并返回零元素,因为该类没有元素.
但$(items[c]).find('.received.unseen')返回undefined和bug.那么这里发生了什么?
编辑:这是我有bug的功能,我切换到jquery 2.1.1:
function updateUnseenBell(){
var m;
for (var c in items)
if (items.hasOwnProperty(c) && (m = items[c].gEbCN("chat-partner-tab")[0])) {
if($(items[c]).find('.received.unseen:not(.shown)').length > 0){
if (!(m.l2_newMsgBell)) {
m.appendChild(m.l2_newMsgBell = newMsgBell.cloneNode());
playSound("message");
}
} else if (m.l2_newMsgBell) {
m.removeChild(m.l2_newMsgBell);
delete m.l2_newMsgBell;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我把它减少到调试的最小值,但仍然得到相同的错误:
function updateUnseenBell(){
for (var c in items) {
if (items.hasOwnProperty(c)) {
if ($(items[c]).find('.received.unseen:not(.shown)').length > 0) {
alert(1);
} else {
alert(2);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
使用
$(items[c]).find('.message.received.unseen')
Run Code Online (Sandbox Code Playgroud)
这应该工作.
解决这个问题的另一种方法是
$(items[c]).find(".received").find(".unseen").find(":not(.sh??own)")
Run Code Online (Sandbox Code Playgroud)
它不是一个优雅的方法,但也有效.
| 归档时间: |
|
| 查看次数: |
10525 次 |
| 最近记录: |