<script>
function changeView()
{
var imgs = document.getElementsByTagName( "img ");
for(var i=0;i <imgs.length;i++)
{
obj = imgs[i].parentElement;
alert(obj.innerText);
//obj.innerText = "fds ";
}
}
</script>
我在本网页中的12个 <IMG> 标签,但是我在此循环中不加//obj.innerText = "fds ";
这行代码它就执行12次,但是加上了这句话它就只执行6次.很不解.....
虽说只是个js,但大家帮助一下啊....等待中.....
------解决方案--------------------
//测试一
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<script>
function changeView()
{
var imgs = document.getElementsByTagName( "img ");
for(var i=0;i <imgs.length;i++)
{
obj = imgs[i].parentElement;
alert(obj.innerText + " "+ imgs.length);
obj.innerText = "fds ";
}
}
changeView()
</script>
结果,imgs.length会减少
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<div> <img src= "http://127.0.0.1/view/js/default/css/default/close.gif "> </div>
<script>
function changeView()
{
var imgs1 = document.getElementsByTagName( "img ");
var imgs = new Array();
for(var i=0;i <imgs1.length;i++){
imgs[imgs.length] = imgs1[i];