<?xml version="1.0" encoding="utf-8" ?>
<bookstore>
<book>
<title>Rain</title>
<year>2010</year>
<author>Martin</author>
</book>
<book>
<title>Cloud</title>
<year>2009</year>
<author>Robert</author>
</book>
<book>
<title>River</title>
<year>2007</year>
<author>Fred</author>
</book>
</bookstore>
如何获取title等于Cloud的元素,我想使用find活filter直接来取,不要使用each来遍历。
在最新浏览器下测试通过:
var xml='<?xml version="1.0" encoding="utf-8" ?><bookstore><book><title>Rain</title><year>2010</year><author>Martin</author></book><book><title>Cloud</title><year>2009</year><author>Robert</author></book><book><title>River</title><year>2007</year><author>Fred</author></book></bookstore>', xmlDoc = $.parseXML( xml ), $xml = $(xmlDoc); var $titles=$xml.find("title").filter(function(index){ return this.textContent=="Cloud" || this.innerText == "Cloud"; }); console.log($titles);
你试试上面的代码吧,我在最新的浏览器上测试通过,机子上没有IE6789,没测