[jQuery] blur , change 事件

[jQuery] blur , change 事件

說明:

  • Blur() : 當物件失去forcus
  • Change():當物件失去focus並且內容改變

範例:

<HEAD>
<script type="Text/JavaScript" src="js/jQuery.js"></script>
<script type="Text/JavaScript">
$(document).ready(function(){
	$('#div1 input').bind('blur',function(){
		$('#span1').html($(this).attr('name') + '=' + $(this).val());
	});
	$('#div2 input').bind('change',function(){
		$('#span2').html($(this).attr('name') + '=' + $(this).val());
	});
})

</script>
</HEAD>
<BODY>
<FORM action="" method=POST id=form1 name=form1>
<div id="div1">
blur<br />
姓名:<input type="text" id="txtName" name="txtName" value="" /><br />
密碼:<input type="password" id="txtPassword" name="txtPassword" value="" /><br />
<span id="span1"></span>
</div>
<hr />
<div id="div2">
change:<br />
姓名:<input type="text" id="txtName2" name="txtName2" value="" /><br />
密碼:<input type="password" id="txtPassword2" name="txtPassword2" value="" /><br />
<span id="span2"></span>
</div>
</FORM>
</BODY>
</HTML>

以下是簽名:


Microsoft MVP
Visual Studio and Development Technologies
(2005~2019/6) 
topcat
Blog:http://www.dotblogs.com.tw/topcat