瑟瑟发抖的小白,第一次在论坛发帖。虚心求教一下这个简单的JS怎么运行不了

a8745324 2016-09-01 12:38:16

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>这个JS怎么运行不了
</title>
</head>

<script type="text/javascript ">
function myjs(){
var a=document.getElementById("a_pic");
var source=a.getAttribute("href");
var b=document.getElementById("b_pic");
b.setAttribute=("src","source");
var description=a.getAttribute("title");
var text=document.getElementById("text");
text.firstChild.nodeValue=description;
}
</script>

<BODY>
<li id="a_pic">
<a href="1.jpg" title="我是第一张图" onClick="myjs(this);return false";>第一张</a>
</li>
<img id="b_pic" src="2.jpg" />
<p id="text">我要第一张图</p>
</BODY>


PS:这段代码我是从javascript DOM编程艺术的书上看到的一段代码。然后自己动手做了一下,发现整个JS脚本运行不了。前前后后看了好多遍,都不知道错在哪了。原文是:原来的图片被替换成<a>链接所指向的一张新图,同时下面的描述性文字也被替换为这个链接的title的属性值。
...全文
76 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
a8745324 2016-09-01
  • 打赏
  • 举报
回复
非常感谢各位
Go 旅城通票 2016-09-01
  • 打赏
  • 举报
回复
    function myjs(a) {//////////////
        //var a = document.getElementById("a_pic");
        var source = a.getAttribute("href");
        var b = document.getElementById("b_pic");
        //b.setAttribute = ("src", "source");
        b.setAttribute("src", "source");
        var description = a.getAttribute("title");
        var text = document.getElementById("text");
        text.firstChild.nodeValue = description;
    }
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>这个JS怎么运行不了</title>
<script type="text/javascript ">
function myjs(){
	var a=document.getElementById("a_pic");
 	var source=a.getAttribute("href");
 	var b=document.getElementById("b_pic");
 	b.setAttribute("src",source);
 	var description=a.getAttribute("title");
 	var text=document.getElementById("text");
 	text.firstChild.nodeValue=description;
	return false;
 }
 </script>
</head>


<BODY>
	<li><a id="a_pic" href="1.jpg" title="我是第一张图" onClick="return myjs(this);">第一张</a></li>
	<img id="b_pic" src="2.jpg" />
	<p id="text">我要第一张图</p>
</BODY>
直接上代码了

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧