2013-04-25 37 views
0

輸入鍵盤點擊按鈕hi2all我需要處理的只是輸入按鈕事件,但我的代碼,處理進入甚至當我點擊手柄只使用jQuery

另一個按鈕,它

例如當我點擊Shift + Enter從KB它處理點擊我要阻止這樣的事情

我想處理緊迫獨自進入

{_ __ _ __ _ __ _ __ 另一個問題 我希望每個附加文本

我的代碼後添加新的生產線在這裏

<!DOCTYPE HTML> 
<html> 

    <head> 
     <meta http-equiv="content-type" content="text/html" /> 
     <meta name="author" content="gencyolcu" /> 
     <title>Untitled 1</title> 
     <style> 
</style> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> 
     <script> 
      $(document).ready(function() { 
       $("#button1").click(function() { 
        $(this).attr("disabled", true); 
       }); 
       $("#entr").keypress(function(e) { 
        if (e.which == 13) { 
         alert("enter pressed"); 
         $("#texts").append($("#entr").val()); 
        } 
       }); 
      }); 
     </script> 
    </head> 

    <body> 
     <div id="m" style="background-color: darkorange;">click me to change webpage background</div> 
     <input id="entr" type="text" value="enter some text here" /> 
     <input id="button1" type="button" value="me" /> 
     <p id="texts">text in text box will appended here 
      <br /> 
     </p> 
    </body> 

</html> 
<script type="text/javascript"> 
    //change the color of webpage when clicking the div 
    var x = document.getElementById("m"); 
    x.addEventListener("click", function() { 
     document.body.style.backgroundColor = "darkturquoise"; 
    }); 
</script> 

回答

0

這裏就是你需要做的事。將您的事件keypress綁定到正文。

jQuery(document).ready(function(){ 
    jQuery('body').on('keypress', function(e){ 
     // We are looking for the action "enter" 
     if(e.which == 13){ 
      // Must not be with shift 
      if(event.shiftKey !== true){ 
       alert(' Enter ! '); 
      } 
     } 
    }); 
}); 

要添加一個新行,你必須要追加MyVar = MyVar + '<br />'+"\r\n";

+0

什麼,如果這個人壓機進入如何讓他只按enter鍵 – TheSniper104 2013-04-25 15:58:32

+0

也任何按鈕,如果什麼用戶按下任何按鈕與回車我想防止那件事情需要他只有按下輸入不僅Shiftkey – TheSniper104 2013-04-25 16:00:35

+0

看看什麼'e'給你訪問。 – 2013-04-26 16:01:36