Home  >  Article  >  Web Front-end  >  鼠标聚焦到Text输入框时,按回车键刷新页面原因及解决方法_html/css_WEB-ITnose

鼠标聚焦到Text输入框时,按回车键刷新页面原因及解决方法_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:54:501225browse

前提 一个form中只有一个输入框,当输入框获取焦点后,点击回车,导致整个页面都刷新,问题解决办法。

1、处理form 


在form中添加事件 

.......


2、增加一个隐藏的输入框,认为改变单个输入框


3、屏蔽回车键


1>  全局去掉回车事件的方法

function document.onkeydown() {

        var e = event.srcElement;

        if (event.keyCode == 13) {

            return false;

        }

    }


2>  去掉输入框的回车事件的方法

onkeydown="return ClearSubmit(event)"



 function ClearSubmit(e) {

            if (e.keyCode == 13) {

                return false;

            }

   }

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn