使用多个选择器的jQuery .find

u3r8eeie  于 2023-11-17  发布在  jQuery
关注(0)|答案(2)|浏览(123)

我遇到了这个问题,Jquery items[c]被很好地定义为HTMLElement,但是当我使用.find和多个选择器时,我得到了这个错误:

  1. TypeError: X[g].exec is not a function
  2. http://code.jquery.com/jquery-latest.min.js

字符串
当我检查一些手表时,我得到了下面图片中的内容:
$(items[c]).find('.received')工作正常,并返回一些元素,因为该类中有元素
$(items[c]).find('.receive')也可以正常工作,并返回零个元素,因为该类中没有元素。
但是$(items[c]).find('.received.unseen')返回undefined和bugs.那么这里发生了什么?


的数据

EDIT:以下是来自调试器firefox

的items[c]中的内容
**编辑:**这里是我有bug的函数,我切换到了jquery 2.1.1:

  1. function updateUnseenBell(){
  2. var m;
  3. for (var c in items)
  4. if (items.hasOwnProperty(c) && (m = items[c].gEbCN("chat-partner-tab")[0])) {
  5. if($(items[c]).find('.received.unseen:not(.shown)').length > 0){
  6. if (!(m.l2_newMsgBell)) {
  7. m.appendChild(m.l2_newMsgBell = newMsgBell.cloneNode());
  8. playSound("message");
  9. }
  10. } else if (m.l2_newMsgBell) {
  11. m.removeChild(m.l2_newMsgBell);
  12. delete m.l2_newMsgBell;
  13. }
  14. }
  15. }


我把它减少到这个最小值进行调试,但仍然得到相同的错误:

  1. function updateUnseenBell(){
  2. for (var c in items) {
  3. if (items.hasOwnProperty(c)) {
  4. if ($(items[c]).find('.received.unseen:not(.shown)').length > 0) {
  5. alert(1);
  6. } else {
  7. alert(2);
  8. }
  9. }
  10. }
  11. }

mwkjh3gx

mwkjh3gx1#

使用

  1. $(items[c]).find('.message.received.unseen')

字符串
这应该行得通
另一种解决方法是

  1. $(items[c]).find(".received").find(".unseen").find(":not(.sh‌​own)")


这不是一个优雅的方法,但也工作。

wtzytmuj

wtzytmuj2#

您可以使用的另一种方法:用途:

  1. $(items[c]).find(".received, .unseen, :not(.sh‌​own)");

字符串

相关问题