2014-01-17 32 views
0

我有這樣的代碼:檢測回車鍵JS - 不工作

<a class="link_standard" id="login">Login</a> 

<div id="loginpop"> 
    <input type="text" id="emaillogin" class="form-control input-sm" />     
    <input type="password" id="pwdlogin" class="form-control input-sm" /> 
</div> 

JS:

$(function(){ 
    $('#loginpop').hide(); 
    $('#login').popover({ 
    html: true, 
    placement: 'bottom', 
    content: function(){ 
     return $('#loginpop').html(); 
    } 
    }); 
    $('#login').on('show.bs.popover', function() { 
    $('#pwdlogin').keydown(function(e){ 
     if(e.keyCode == 13){ 
     alert('test enter'); 
     } 
    }); 
    }); 
}); 

我要的是:

後,我輸入密碼,如果我打輸入密鑰,它應該警告('測試輸入'),但它不起作用。我究竟做錯了什麼?

回答

0

我解決了,野人是:

$('#login').on('shown.bs.popover', function() { 
      $('#pwdlogin').keydown(function(e){ 
      if(e.keyCode == 13){ 
       alert('test enter'); 
      } 
      }); 
     }); 

showshown

0

試試這個

$(function(){ 
$('#loginpop').hide(); 
$('#login').popover({ 
    html: true, 
    placement: 'bottom', 
    content: function(){ 
     return $('#loginpop').html(); 
    } 
}); 

    $('#pwdlogin').keydown(function(e){ 
     if(e.keyCode == 13){ 
     alert('test enter'); 
     } 
    }); 

}); 
1

$('#pwdlogin').keydown應該$(function(){塊是直接。

+0

亙古不變的工作,這是我第一次嘗試..彈出窗口是隱藏的,這就是爲什麼在事件處理程序後應'附'的.html();'' – doniyor