Jquery焦點與失去焦點

$(function(){
$("#input").focus(function(){//#input換成你的input的ID
//這裏寫獲得焦點之後運行的代碼。
}).blur(function(){
    //$(".scroll-question").css("display","none");
    });
})

})



live要1.4才支持,以下ie,firefox都沒問題
<!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="/js/jquery-1.4.4.js"></script>
<script>
$(document).ready(function()
{
 $("#nameBefore").dblclick(function()
 {
  $("#nameBefore").replaceWith("<div id='nameIn'><input type='text' name='nameInVal' id='nameInVal' value='In' /></div>");
 }
 );
 //失去焦點以後
 $("#nameInVal").live("blur",function()
 {
  alert('nameInVal已失去焦點');
 }
 );
}    
);
</script>
</head>
<body>
<form name="testfm" method="post" action="save.php">        
<table>
<tr><td>1</td><td><div id='nameBefore'>Before</div></td></tr>
</table>
</form>    
</body>
</html> 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章