Asp.Net 文本框按回车键响应按钮单击操作的方法

来源:互联网 发布:树莓派tensorflow 编辑:程序博客网 时间:2024/05/16 23:02

需要使用Javascript来实现

 

第一步:

在<head></head>里添加Javascript函数

 

    <script type="text/javascript">
        function doButton()
        {
            if (event.keyCode == 13)
            {
                document.getElementById("Button1").click();
                return false;
            }
        }
    </script>

 

return false 是让浏览器取消对回车键原本的提交表单的操作。

 

第二步:

在"Code窗口" Page_Load 里添加需要响应的文本框TextBox1的keydown事件

TextBox1.Attributes.Add("onkeydown", "return doButton()");

 

原创粉丝点击