jquery 零碎笔记

toggle使用

<!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=gb2312" />
<title>无标题文档</title>
</head>

<body>
<button value="click" onclick="$('#testdiv').toggle(c1,c2,c3);">123</button>
<div id="testdiv" style="background-color:red">1231231</div>
<script type="text/javascript" language="javascript">
	function c1(){
		$('#testdiv').css('background-color','blue');
	}
		function c2(){
		$('#testdiv').css('background-color','green');
	}
		function c3(){
		$('#testdiv').css('background-color','red');
	}
</script>
</body>
<script type="text/javascript" language="javascript" src="jquery-1.7.2.min.js"></script>
</html>

bind 和unbind 新用

通过bind绑定事件时,可以加上后缀(例:.btn),这就相当于将事件分组,组名就是.btn,到取消的时候就可以通过unbind('.btn')取消所有此组内的事件。
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").bind("click.btn mouseover.btn",function(){
   alert(123333);
  });
 $('#btn').unbind('.btn');
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button id="btn">请点击这里1111</button>
<button  id="btn123">请点击这里</button>
</body>
</html>


 

posted @ 2013-09-29 17:30  skyding  阅读(140)  评论(0编辑  收藏  举报