jquery的链式操作以及事件绑定

时间:2023-12-29 22:18:56
 <!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 type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script> $(function(){ //$('div').find('h3').eq(2).css('background','red'); /*var oDiv = $('div');
var aH3 = oDiv.find('h3');
var oH3_2 = aH3.eq(2);
oH3_2.css('background','red');*/ $('div').find('h3').eq(2).css('background','red').end().eq(4).css('background','green').end().end().css('border','1px red solid');
//事件绑定
$('.txt').bind('focus',{msg1:'I am msg1',msg2:'我是msg 2'},function(e){
$('#divTip').show().html(e.data.msg1);
});
}); </script>
</head> <body>
<div>
<h3>11111</h3>
<h3>22222</h3>
<h3>33333</h3>
<h3>44444</h3>
<h3>55555</h3>
</div> <div>姓名:<input type="text" class="txt" /></div>
<div id="divTip" class="clsTip"></div>
</body>
</html>