When the mouse focus to the TextBox input box, press the Enter key to refresh the page causes and solutions

Original: https://blog.csdn.net/xuezhongsong/article/details/6859037

Problem: When the mouse focus to the TextBox input box, press the Enter key to refresh the page

The reason: Only when a TextBox input box, when the entry is complete, press the Enter key will automatically submit the form when the form, then refresh the page

Solution:

1, form processing add the event in the form

 <form onsubmit="return false;"></form>

2, add a hidden input box

<input id="hiddenText" type="text" style="display:none" />

3, the shield ENTER

3.1, remove the Enter event of a global

function document.onkeydown() {
    var e = event.srcElement;
        if (event.keyCode == 13) {
        return false;
    }
}

3.2, remove Enter event input box method

onkeydown="return ClearSubmit(event)"
<input type="text"  onkeydown="return ClearSubmit(event)" />

 function ClearSubmit(e) {
    if (e.keyCode == 13) {
        return false;
    }
}

Guess you like

Origin www.cnblogs.com/mg007/p/11130505.html