视图页面内我有几个DIV其ID的开始与my-
前缀,访问儿童属性值
<div id="my-div1"><img src="/img/1.jpg" /></div>
<div id="my-div2"><img src="/img/2.jpg" /></div>
<div id="my-div3"><img src="/img/3.jpg" /></div>
在js代码
我迭代槽每一个元素,我想申请某一功能子img元素,在这种情况下,直道
$(document).ready(function() {
$('div[id^="my-"]').each(function() {
$(this).css("background-size", "100% 100%");
$(this).css("background-repeat", "no-repeat");
// this doesn't work
$(this).children("img").backstretch($(this).attr('src'));
})
});
当我测试的每个格下的IMG $(this).children("img").length
回报实际数目,但我不知道如何通过它的src属性值直道功能?
jquery中的后背? –
http://srobbin.com/jquery-plugins/backstretch/ – user1765862