标签:head xhtml remove attr this doctype color cli type
为按钮挂事件和移除事件
<body>
<input type="button" value="挂事件" id="gua" />
<input type="button" value="测试事件" id="ceshi" />
<input type="button" value="移除事件" id="yichu" />
</body>
<script type="text/javascript">
//点击给测试事件添加
$("#gua").click(function(){
$("#ceshi").bind("click",function(){
alert ("挂上了事件");
});
})
//点击移除 移除刚刚给测试事件挂上的事件
$("#yichu").click(){
$("#ceshi").unbind("click");
})
</script>
实现点击色块
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script src="jquery-1.11.2.min.js"></script> <style type="text/css"> .aa{ width:200px; height:200px; float:left; margin:5px; background-color:#3F6} </style> </head> <body> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <input type="button" value="测试" onclick="test()" /> </body> <script type="text/javascript"> $(".aa").click(function(){ //将所有元素的背景色变成原来的颜色 $(".aa").removeAttr("xz"); $(".aa").css("background-color","#3f6"); //找到点击了谁 $(this).css("background-color","yellow"); $("[xz=‘1‘]").css("background-color","red"); })
标签:head xhtml remove attr this doctype color cli type
原文地址:http://www.cnblogs.com/xiaoming-6/p/6267216.html