设 A = $("#id a"),B = $("#id .c a"),求 A - B。

要求:1、不能用 jQuery 等框架;

           2、兼容 IE6 在内的各大浏览器;

           3、尽可能高效;

           4、尽可能简短。

 

解法一(由檬檬提供):

 1 var b = document.getElementById("id"),
 2     a = b.getElementsByTagName("a"),
 3     result = [];
 4 
 5 o: for (var i = 0, j = a.length; i < j; i++) {
 6     var c = a[i].parentNode;
 7     while (c && c != b) {
 8         if ((" " + c.className.toLowerCase() + " ").indexOf(" c ") >= 0) {
 9             continue o;
10         }
11         c = c.parentNode;
12     }
13     result.push(a[i]);
14 }
15 console.log(result);

 

其他解法 米棕my

 

相关文章:

  • 2022-12-23
  • 2021-08-03
  • 2021-11-16
  • 2022-12-23
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-09
  • 2021-12-11
  • 2022-01-21
  • 2021-09-14
  • 2021-09-05
  • 2022-12-23
  • 2021-12-26
相关资源
相似解决方案