SoFunction
Updated on 2025-02-28

JS code that prohibits space submission form

When working on the project, I used ckeditor on a page, but the problem came. I pressed the Enter key wherever there was a text box and it would refresh automatically. Finally, I found a solution:
Copy the codeThe code is as follows:

<input type="text" name="" value="<s:property value=''/>" class="InputStyle" onkeydown="keydown(this)"

It means that as long as you bind each input text box, the onkeydown() event.js code determines whether it is 13. The code is as follows:
Copy the codeThe code is as follows:

function keydown(text){
$j(text).keydown(function(e){
if(==13){
();
}
});
}

I use jquery. Because many times, we use event events, which are incompatible with other browsers, so using jquery which can be used to use various browsers to use various browsers