我觉得下面两段代码本质上应该是一样的,就是变量的一个赋值有点不一样,但是测试的时候代码段1是出不来的,而代码段2是可以实现我的目标的 这是为什么?代码段1:function showPic(whichpic){ var source = whichpic.getAttribute("href"); var placeholder = document.getElementById("placeholder"); placeholder.setAttribute("src",source); var text = whichpic.getAttribute("title"); var description = document.getElementById("description").firstChild.nodeValue; description = text;}代码段2:function showPic(whichpic){ var source = whichpic.getAttribute("href"); var placeholder = document.getElementById("placeholder"); placeholder.setAttribute("src",source); var text = whichpic.getAttribute("title"); var description = document.getElementById("description"); description .firstChild.nodeValue= text;}
3 回答
橋本奈奈未
TA贡献436条经验 获得超108个赞
var description = document.getElementById("description").firstChild;
description.nodeValue= text;
这样写也是能达到效果
添加回答
举报
0/150
提交
取消