我有一个包含一些 HTML 的数组,如下所示:
var array=[
"<div anAttribute=19 class='foo'>This is the content of the foo div.</div>",
"<div anAttribute=14 class='bar'>This is the content of the bar div.</div>"
];
我想获取它们两个的 anAttribute 值。
array[0].$('.foo').attr("anAttribute");
将返回 19。
最佳答案
你可以这样做:
$(array[0]).attr("anAttribute");
$(array[1]).attr("anAttribute");
我假设 anAttribute
是一个有效的 html 属性,如果没有使用 data-*
前缀的话。
关于javascript - 在存储在数组中的 HTML 上使用 jQuery 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17439100/