jQuery的单击触发事件学习和例

    <body>
<div></div>
<div id="b"></div>
<div></div>
<div></div>
<div></div>
<div></div>
</body>
<style>
div
{height:100px;width:100px;border:1px solid #ccc;margin-bottom:10px; background-color:white; cursor:pointer;}
</style>
<script type="text/javascript">
$(function(){//记得将事件放在function里面。
$("div").click(function(){
if($(this).is("#b")){$(this).css("backgroundColor","red");}
else{$(this).css("backgroundColor","green");}
})
})

/*$(function(){
$("#b").click(function(){
$("#b").css("backgroundColor","#f60")
})
})
*/
</script>





posted @ 2012-03-29 14:47  纯属偶然_黄勇  阅读(244)  评论(0编辑  收藏  举报