码迷,mamicode.com
首页 > Web开发 > 详细

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

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

标签:icon   and   turn   click   blog   元素   esc   state   nbsp   


<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

标签:icon   and   turn   click   blog   元素   esc   state   nbsp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!