我有一些XML如下所示。如果我知道title属性是:c4d5c5如何获取mode属性(四个)?
<swatch title="af588b" name="color" width="50" height="50" mode="one"></swatch>
<swatch title="b1977c" name="color" width="50" height="50" mode="two"></swatch>
<swatch title="bfca64" name="color" width="50" height="50" mode="three"></swatch>
<swatch title="c4d5c5" name="color" width="50" height="50" mode="four"></swatch>
<swatch title="c5dbd9" name="color" width="50" height="50" mode="five"></swatch>
<swatch title="c181a4" name="color" width="50" height="50" mode="six"></swatch>
<swatch title="ca936c" name="color" width="50" height="50" mode="seven"></swatch>
这样的东西? (这不起作用,但这就是我现在所处的位置)
$(xmlDoc).find('swatch').each(function() {
var myMode = $(xmlDoc).find('mode[title="c4d5c5"]');
console.log(myMode+" myMode");
});
答案 0 :(得分:0)
您需要将attribute equals selector与swatch
一起使用,然后使用.attr()来读取属性值,如
var mode = $(xmlDoc).find('swatch[title="c4d5c5"]').attr('mode');