$(function(){
var Len=$(".hint--bottom-left");
var img=$(".hint--bottom-left>img");
var ary=[];
for(var i=0;i<Len.length;i++){
var title=Len[i].getAttribute("aria-label");
var imgsrc=img[i].getAttribute("src");
ary.push({imgtitle:title,src:imgsrc})
};
console.log(ary)
})
问题:
获取Len的aria-label属性值
获取img的属性值
把获取的数据以这种形式存储:
ary=[{imgtitle:图片路径1,src:图片名字1},{imgtitle:图片路径2,src:图片名字2},{imgtitle:图片路径3,src:图片名字3}....]
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="http://www.w3school.com.cn/jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(function () {
var Len = $(".hint--bottom-left");
var img = $(".hint--bottom-left>img");
var ary = [];
for (var i = 0; i < Len.length; i++) {
var title = $(Len[i]).attr("aria-label");
var imgsrc = $(img[i]).attr("src");
ary.push({ imgtitle: title, src: imgsrc })
};
console.log(ary);
});
</script>
</head>
<body>
<div class="hint--bottom-left" aria-label="大秦宣太后">
<img src="Images/大秦宣太后.jpg" />
</div>
<div class="hint--bottom-left" aria-label="海洋之心">
<img src="Images/海洋之心.jpg" />
</div>
</body>
</html>