按钮的按键(输入)问题 [英] Problem with keypress (enter) for a asp button

查看:65
本文介绍了按钮的按键(输入)问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过互联网获得了这个代码并进行了一些搜索,我一直在我的网站中使用它在两个单独的地方。它工作得很好但是当把它放到另一个地方它只是拒绝工作,我不明白为什么。任何人都可以帮我解决这个问题吗?



这是按下enter键按一下按钮



我的javascript代码

I got this code over the internet with some seaching and I have been using it in my website in two seperate places. It works very well but when putting it into another place it just refuses to work and I can not see why. Can anyone please help me figure this out??

This is to make a button click on "enter" key press

My javascript code

<<pre lang="cs">script>
          $(document).ready(function () {
              $("#password2").keydown(function (e) {
                   setEnterValue(e);
               });
           });

           function setEnterValue(e) {
               var key = checkBrowser(e);
               if (key == 13) {
                   $("#btnLogin").click();
               }
           }
           function checkBrowser(e) {
               if (window.event)
                   key = window.event.keyCode;     //IE
               else
                   key = e.which;     //firefox
               return key;
           }
    </script></pre>



我的HTML代码




My html code

<input type="password" placeholder="Password" name="password" id="password1" runat="server"/> 
<input type="password" placeholder="Confirm" name="password" id="password2" runat="server"/> 
<asp:Button ID="btnLogin" runat="server" Text="Change" OnClick="btnChange_Click" /> 

推荐答案

document )。ready( function (){
(document).ready(function () {


#password2)。keydown( function (e){
setEnterValue(e);
});
});

function setEnterValue(e){
var key = checkBrowser (E);
if (key == 13 ){
("#password2").keydown(function (e) { setEnterValue(e); }); }); function setEnterValue(e) { var key = checkBrowser(e); if (key == 13) {


#btnLogin)。click();
}
}
function checkBrowser(e){
if window .event)
key = window .event.keyCode; // IE
else
key = e.which; // firefox
return 键;
}
< / script> < / pre >
("#btnLogin").click(); } } function checkBrowser(e) { if (window.event) key = window.event.keyCode; //IE else key = e.which; //firefox return key; } </script></pre>



我的HTML代码




My html code

<input type="password" placeholder="Password" name="password" id="password1" runat="server"/> 
<input type="password" placeholder="Confirm" name="password" id="password2" runat="server"/> 
<asp:Button ID="btnLogin" runat="server" Text="Change" OnClick="btnChange_Click" /> 


这篇关于按钮的按键(输入)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆