2013-04-25 36 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