在高级表达式不能满足你的要求,或者某个库不支持某个表达式的情况下,还可以使用回调函数来选择DOM元素。

使用YUI的YAHOO.util.Dom.getElementsBy方法,选择只包含一个图像子元素的所有锚标签。

YAHOO.util.Dom.getElementsBy(function(e){

  return(e.nodeName='A' && e.getElementsByTagName('img').length == 1)

})

 使用jquery的filter方法:

$('a').filter(function(){

  return($('img',this).length==1)

})

 

相关文章:

  • 2021-05-23
  • 2022-12-23
  • 2022-01-19
  • 2021-12-29
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-28
  • 2021-12-23
  • 2022-01-18
  • 2021-11-19
  • 2022-02-26
相关资源
相似解决方案