为了账号安全,请及时绑定邮箱和手机立即绑定

同样的代码,id为content部分写的时候能正常运行,现在又突然不能了呢,代码单独拷贝又可以了

同样的代码,id为content部分写的时候能正常运行,现在又突然不能了呢,代码单独拷贝又可以了

慕田峪7238772 2016-12-04 19:02:49
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <style type="text/css"> div{  width:1000px;  margin:0 auto;  } </style> </head> <body> <div> <h2 id="content">javascript能够改变html的内容。</h2> <script> function myFunction() {  x=document.getElementById("content");  x.innerHTML="hello javascript!";  } </script> <button type="button" onclick="myFunction()">点击这里</button> <h2>javascript设置点击改变图片</h2> <script> function changeimages() {  element=document.getElementById("img")  if (element.src.match("3"))  {      element.src="images/2.jpg";   }  else{   element.src="images/3.jpg";   }    } </script> <img id="img" onclick="changeimages()" src="images/2.jpg" > <h2 id="manner">javascript能够改变html的样式</h2> <script> function myFunction() {  x=document.getElementById("manner");  x.style.color="red";  } </script> <button type="button" onclick="myFunction()">点击这里</button> </div> </body> </html>
查看完整描述

3 回答

已采纳
?
lllqw

TA贡献6条经验 获得超4个赞

18行跟42行的function重名,所以第一个被覆盖。改掉一个名字就好了,最好是都改成有语义的函数名。而且变量最好要定义

查看完整回答
2 反对 回复 2016-12-04
  • lllqw
    lllqw
    记得标签的onclick属性也要改
?
stone310

TA贡献361条经验 获得超191个赞

两个同名函数声明function myFunction(),后面的覆盖前面

查看完整回答
1 反对 回复 2016-12-04
  • 3 回答
  • 0 关注
  • 1484 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信