2014-05-06 55 views
0

我的J-Query按鍵,shift鍵在Mozilla中無法運行Firefox需要幫助,提前致謝。不工作jquery回車鍵和Shift-Enter鍵

J-查詢使用:jQuery的1.7.2.min.js

<html><body> 
<textarea id = 'text' rows='4' cols='50' style = 'width: 50%;height:15%;' placeholder = 'Enter Post....'></textarea> 
</body></html> 

<script> 

$('#text').keypress(
    function(e){ 
     if (e.keyCode == 13 && e.shiftKey) { 
      alert("a"); 
     } 
     else if(e.keyCode == 13){ 
      alert("sdf"); 
     } 
    } 
); 

</script> 

回答

0

將您的代碼在文檔準備好處理程序 -

$(document).ready(function() { 
    $('#text').keypress(function (e) { 
     if (e.keyCode == 13 && e.shiftKey) { 
      console.log("a"); 
     } else if (e.keyCode == 13) { 
      console.log("sdf"); 
     } 
    }); 
}); 
0

試試這個

$('#text').keypress(function(event) { 
     if (event.keyCode == 13 && event.shiftKey) { 
     alert("shift plus enter"); 
     } 
}); 
+0

不工作.. :( – user246186

+0

我的壞...更新了代碼。請你檢查? – maj