selector + traversal
$('div').each(function (i){
i就是索引值
this 表示获取遍历每一个dom对象
});
$('div').each(function (index,domEle){
index就是索引值
domEle 表示获取遍历每一个dom对象
});
Another traversal method
1) First get a collection object
2) Traverse each element of the collection object
var d=$("div");
$.each(d,function (index,domEle){
d是要遍历的集合
index就是索引值
domEle 表示获取遍历每一个dom对
});
For string splicing problems, you can use double quotes and single quotes, and use them when appropriate.
Code used this time:
$(function(){
$('.shiting').each(function (i){
$(this).html('<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id='+ $(this).attr("data-songid") +'&auto=0&height=66"></iframe>')
});
})
When writing a website to embed NetEase Cloud code, due to website optimization, the page needs to use less iframe framework, so I have to use jQuery to dynamically embed it.