防止所有文本框上的回发 [英] Preventing postback on all textboxes

查看:74
本文介绍了防止所有文本框上的回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我使用以下脚本(基于我在此处找到的文章)来防止在按下回车键时对所有文本框进行回发。 (搜索文本框除外)。

Hello,

I used the following script (based on articles I found here) for preventing postback on all textboxes when enter key is pressed. (except search textbox).

 <script type="text/javascript">
     $(function () {
         $(':text').bind('keydown', function (e) {
             //on keydown for all textboxes
             if (e.target.className != "searchtextbox") {
                 if (e.keyCode == 13) { //if this is enter key
                     e.preventDefault();
                     return false;
                 }
                 else
                     return true;
             }
             else
                 return true;
         });
     });
</script>





我正在使用内容页面,我在ContentPlaceHolder上添加了脚本,但它没有似乎是为了防止回发。



我需要设置更多设置才能使脚本正常工作吗?



提前谢谢。



I'm using a content page and I added the script on ContentPlaceHolder, but it doesn't seem to prevent postback.

Are there more settings I need to setup in order the script to work?

Thank you in advance.

推荐答案

(function(){
(function () {


(':text')。bind ('keydown',函数(e){
//在所有文本框的keydown上
if(e.target.className!=searchtextbox){
if(e.keyCode == 13){//如果这是输入键
e.preventDefault();
返回false;
}
else
返回true;
}
else
返回true;
});
});
< / script>
(':text').bind('keydown', function (e) { //on keydown for all textboxes if (e.target.className != "searchtextbox") { if (e.keyCode == 13) { //if this is enter key e.preventDefault(); return false; } else return true; } else return true; }); }); </script>





我正在使用内容页面,我在ContentPlaceHolder上添加了脚本,但它没有似乎是为了防止回发。



我需要设置更多设置才能使脚本正常工作吗?



提前谢谢。



I'm using a content page and I added the script on ContentPlaceHolder, but it doesn't seem to prevent postback.

Are there more settings I need to setup in order the script to work?

Thank you in advance.


你试过按键吗?

Keypress适合我。



考虑使用.not选择器省略.searchtextbox

这样的事情:

Did you try keypress?
Keypress works for me.

Consider using the .not selector to omit .searchtextbox
Something like this:


这篇关于防止所有文本框上的回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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