当前位置: 代码迷 >> Java Web开发 >> 郁闷很久.请大家帮忙看一下,等待中.该如何处理
  详细解决方案

郁闷很久.请大家帮忙看一下,等待中.该如何处理

热度:162   发布时间:2016-04-17 16:29:20.0
郁闷很久....请大家帮忙看一下,等待中......
<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];
  相关解决方案