WordPress, press Ctrl+enter and return to submit a message

Source: Internet
Author: User
Tags comments php file

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.