点赞功能:
<body>
<input id="btn" type="button" onclick="addLike()" value="13">
<script>
function addLike() {
var btn = document.getElementById("btn");
if (!btn.className) {
btn.value = parseInt(btn.value) + 1;
btn.className = "liked";
} else {
btn.value = parseInt(btn.value) - 1;
btn.className = "";
}
}
</script>
</body>
效果:
点赞前: 点赞后:
收藏功能:
(要引入jquery<script typet="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>)
<head>
<script typet="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"> </script>
</head>
<body>
<p class="like">❤</p>
<script>
$(function () {
$(".like").click(function () {
$(this).toggleClass('cs');
})
})
</script>
</body>
<style>
.like{
font-size:66px;
color:#ccc;
cursor:pointer;
}
.cs{
color:#f00;
}
</style>
效果:
收藏前: 收藏后:
---------------------本文完---------------------