I have some XML as below. If I know the title attribute is: c4d5c5 how do I get the mode attribute (four)?
<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>
Something like this? (this does not work but this is where I am at the moment)
$(xmlDoc).find('swatch').each(function() {
var myMode = $(xmlDoc).find('mode[title="c4d5c5"]');
console.log(myMode+" myMode");
});
您需要将属性equals选择器与swatch
使用,然后使用.attr()来读取属性值,例如
var mode = $(xmlDoc).find('swatch[title="c4d5c5"]').attr('mode');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.