用jquery给选中的元素添加id,但是document.getElementById()无法获取到 50
html:<divclass="cover"><imgsrc="images/images_13_big.png"alt="img13"/><imgsrc="images...
html:
<div class="cover">
<img src="images/images_13_big.png" alt="img13"/>
<img src="images/images_14_big.png" alt="img14"/>
<img src="images/images_15_big.png" alt="img15"/>
<img src="images/images_16_big.png" alt="img16"/>
<img src="images/images_17_big.png" alt="img17"/>
<img src="images/images_18_big.png" alt="img18"/>
</div>
jquery:
//给选中的元素加id
$(".cover img").eq(i).attr({"id":"oImg"});
//使用getElementById()
var oImg = document.getElementById('oImg');
oImg.style.left = 10 + 'px';
提示:Uncaught TypeError: Cannot read property 'style' of null
直接在html里某一个img写上<img id="oImg" src="images/images_13_big.png" alt="img13"/>才能用,但就限死这个元素了 展开
<div class="cover">
<img src="images/images_13_big.png" alt="img13"/>
<img src="images/images_14_big.png" alt="img14"/>
<img src="images/images_15_big.png" alt="img15"/>
<img src="images/images_16_big.png" alt="img16"/>
<img src="images/images_17_big.png" alt="img17"/>
<img src="images/images_18_big.png" alt="img18"/>
</div>
jquery:
//给选中的元素加id
$(".cover img").eq(i).attr({"id":"oImg"});
//使用getElementById()
var oImg = document.getElementById('oImg');
oImg.style.left = 10 + 'px';
提示:Uncaught TypeError: Cannot read property 'style' of null
直接在html里某一个img写上<img id="oImg" src="images/images_13_big.png" alt="img13"/>才能用,但就限死这个元素了 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询