Press Ctrl + Enter and press Enter to submit a message.

Source: Internet
Author: User
Tags comments php file

The implementation method is very simple, just a few lines of javascript can be done. Add this shortcut key to WordPress:
1. Open the comments. Php file in the template and find the following content. The code is as follows:

<Form action = "<? Php echo get_option ('siteurl');?> /Wp-comments-post.php "method =" post "id =" commentform "name =" commentform ">
<? Php if ($ user_ID):?>

If your form tag does not have the name = "commentform" attribute, add it.
2. Pull down a bit and you can see two similar lines. The code is as follows:

<P> <textarea name = "comment" id = "comment" cols = "55" rows = "10" tabindex = "4"> </textarea> </p>
<P> <input type = "submit" id = "submit" tabindex = "5" value = "submit message"/> </p>

If the textarea tag does not have the id attribute, add it according to the above content. If name = "submit" is found in the second line, delete it. If you find it still does not work, change id = "submit" to id = "submitit.

3. At last, add the following javascript code under form and save it. The code is as follows:

<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>

For other information, see JQuery press enter to submit the form. The code is as follows:

$ ("Body"). bind ('keyup', function (event ){
If (event. keyCode = 13 ){
Document. form. submit ();
}    
});

Principle: add a keyup event to the body
The code is as follows:

<Body onkeyup = "autosubmit ()"> // add a listener event
Function autosubmit () {// event-triggered function
If (event. keyCode = 13 ){
Document. form. submit ();
  }    

The code for js implementation is as follows:

<Form action = http://www.111cn.net method = "post" name = "myForm">
<Input type = "text"/>
<Input type = "submit" value = "submit" name = "tijiao"> <font color = "#999999"> press enter to submit the form </font>
</Form>
</Body>
</Html>
<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 the entry from submitting a form for page creation, it is to listen to the onkeydown event of the form, and add onkeydown = "if (event. keyCode = 13) return false;" then OK.

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.