DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript綜合知識 >> jquery 文本框回車與change事件
jquery 文本框回車與change事件
編輯:JavaScript綜合知識     

   文本框的改變用change事件

  要用bind,兩個是有區別的,change只是在失去焦點的時候出發,很多時候不能滿足需要。

 代碼如下  

$('#flowfromid').bind("propertychange",function(){

//你的內容

});

  文本框回車事件

 代碼如下  

$(document).ready(function () {
$("#txt_JumpPager").keydown(function (e) {
var curKey = e.which;
if (curKey == 13) {
$("#lbtn_JumpPager").click();
return false;
}
});
});

  補充還有一些像

  $("#txtEmail").trigger("focus"); //默認時文本框獲得焦點

  $("#txtEmail").focus(function () { //文本框獲取焦點事件

  都是非常好用的

 代碼如下  

<input id="username" type="text" />
<input id="pass" type="password" />
<textarea id="msg" rows="2" cols="20"></textarea>
例子

<script type="text/javascript">
    $(function(){
        $(":input").focus(function(){
              $(this).addClass("focus");
        }).blur(function(){
              $(this).removeClass("focus");
        });
    })
</script>

  用:input匹配所有的input元素,當獲取焦點時,就添加樣式focus,通過$(this)自動識別當前的元素。focus()方法是獲取焦點事件發生時執行的函數。blur()方法是失去焦點事件發生時執行的函數。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved