First, open the comments.php file in the template, find the following content:
The code is as follows |
Copy Code |
<form action= "<?php echo get_option (' SiteURL ');? >/wp-comments-post.php" method= "post" id= "Commentform" name = "Commentform" > <?php if ($user _id):?> |
If you do not have the name= "Commentform" attribute in your form tag, please add it.
Two, and then down a little, you can see a similar line:
The code is as follows |
Copy Code |
<p><textarea name= "comment" id= "comment" cols= "" "rows=" "tabindex=" 4 "></textarea></p> <p><input type= "Submit" id= "Submit" tabindex= "5" value= "Submit Message"/></p> |
If there is no id attribute on the TEXTAREA label, please follow the above section. If you find Name= "submit" in the second line, delete it. If you find it or not, put the id= "submit" to Id= "Submitit", so it must be OK.
Third, finally, under </form>, add the following JavaScript code and save it.
The code is as follows |
Copy Code |
<script type= "text/javascript><!--//--><! [cdata[//><!-- var Commenttextarea = document.getElementById (' comment '); Commenttextarea.onkeydown = function Quicksubmit (e) { if (!e) var e = window.event; if (e.ctrlkey && e.keycode = 13) { document.getElementById (' Submit '). Click (); } }; --><!]] > </script>
|
Other reference jquery return submit Form
The code is as follows |
Copy Code |
$ ("body"). Bind (' KeyUp ', function (event) { if (event.keycode==13) { Document.form.submit (); } }); |
Principle: Add KeyUp event for body
Without the jquery method:
The code is as follows |
Copy Code |
<body onkeyup= "Autosubmit ()" >//Add a listener event function Autosubmit () {//Event trigger functions if (event.keycode==13) { Document.form.submit (); } } |
JS Implementation method
code is as follows |
copy code |
<form Action=http://www.111cn.net method= "POST" name= "MyForm" > <input type= "text"/> <input type= " Submit "value=" Name= "Tijiao" ><font color= "#999999" > Press RETURN Submission Form </font> </form> </ Body> <script language= "JavaScript" type= "Text/javascript" > Document.onkeydown = function (evt) { var evt = window.event?window.event:evt; if (evt.keycode==13) { document.forms["MyForm"].submit (); } </script> |
If you want to prevent enter from submitting a form to do a page, it is listening to the onkeydown event of the form, plus onkeydown= "if (Event.keycode =) return false;" OK