首页 > Web开发 > 详细

js动态改变元素属性img标签的src

时间:2017-04-05 20:46:49      阅读:371      评论:0      收藏:0      [点我收藏+]

<head>
<title>
just a test!
</title>
<script type="text/javascript">
/**
* function:when you open the page,get user‘s data from database
*/
function set_follow(){
var count=0;// you should read it from database
document.getElementById("follow_count").innerHTML=count;
}
/**
* function:change the state of follow
* @return {[type]} [description]
*/
function change_follow(){
var follow=document.getElementById("follow");
var follow_count=document.getElementById("follow_count")
var follow_src_path=follow.src;
follow_src_name=follow_src_path.split("/");
if(follow_src_name[follow_src_name.length-1]=="icon_like.png"){//if you dislike it,set "unlike" and follow_count--
follow.src="icon_unlike.png";
follow_count.innerHTML--;
}
else{//if you like it,set "like" and follow_count++
follow.src="icon_like.png";
follow_count.innerHTML++;
}
}
</script>
</head>
<body>
<div onload="set_follow()">
<ul>
<li><img src="icon_unlike.png" id="follow" onclick="change_follow()">

</img></li>
<li id="follow_count">0</li>
</ul>
</div>
</body>

 

 

js动态改变元素属性img标签的src

原文:http://www.cnblogs.com/wyycatch/p/6602722.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!