【问题标题】:Master page button event Overloading by content page button event when enter key is pressed母版页按钮事件 按下回车键时内容页按钮事件重载
【发布时间】:2015-08-09 22:22:01
【问题描述】:

我有两个搜索选项: 1. 在母版页上有一个文本框和搜索按钮。 2. 在内容页面上,有两个 texboxes 和一个搜索按钮的表单。

现在,每当我从键盘按回车键时,都会触发母版页按钮事件。 我的意思是在每种情况下,当我从键盘按下回车键时,都会调用相同的事件。 我想要如果有人填写内容页面搜索表单并按回车键,它会触发内容页面事件。我这样做是这样的:

<script language="javascript">
        function HandleEnterKey(e) {

            var key;

            if (window.event)
                key = window.event.keyCode;     //IE
            else
                key = e.which;     //firefox

            if (key == 13) {

                if (txtSearchHasFocus) {
                    alert(txtSearchHasFocus);                   
                    document.getElementById("ctl00_bluheader1_btnSearch1").click();
                }
                else if (txtBusinessNameHasFocus || txtLicNumberHasFocus) {
                alert(txtBusinessNameHasFocus);
                alert(txtLicNumberHasFocus);
                alert(document.getElementById("ctl00_ContentPlaceHolder1_btnSearch"));
                e.cancel = true;               
               document.getElementById("ctl00_ContentPlaceHolder1_btnSearch").click();

                }
                else return false;
            }
            //return false;    
        }
    </script>

但不工作 请有人帮助我...

问候

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    您似乎拥有整个文档的 KeyPress 事件处理程序。您应该只为您的特定文本框处理 KeyPress。 IE。您应该为母版页文本框和内容页文本框使用不同的事件处理程序。这是一个使用 jQuery 的示例:

      <script language="javascript" type="text/javascript"> 
            $(document).ready(function() {
                $('#tbMasterId').keypress(function(e) {
                    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                        $('#ctl00_bluheader1_btnSearch1').click();
                        return false;
                    } else {
                        return true;
                    }
                });
               $('#tbContent1Id,#tbContent2Id').keypress(function(e) {
                    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                        $('#ctl00_ContentPlaceHolder1_btnSearch').click();
                        return false;
                    } else {
                        return true;
                    }
                });
            });
        </script>
    

    【讨论】:

      猜你喜欢
      • 2011-08-06
      • 1970-01-01
      • 1970-01-01
      • 2010-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-29
      相关资源
      最近更新 更多