Comment Box Add Ctrl+enter submit function

Source: Internet
Author: User

After writing a comment can not press CTRL + ENTER submit, to take a mouse point, it is painful things, do not know how many lazy people to dismiss the enthusiasm.
Want to add this feature to your comment box, then start:

Open the comments.php file in the topic, press Ctrl+f to search for "textarea", and then add the following code to his back:

The code is as follows Copy Code

Onkeydown= "If" (event.ctrlkey&&event.keycode==13)
{document.getElementById (' Submit '). Click (); return false}; "

Add the above code to your form as

<input/> and so on.


If I press ENTER to submit, I'll just change the top.

The code is as follows Copy Code

Onkeydown= "If" (event.keycode==13)
{document.getElementById (' Submit '). Click (); return false}; "

Save submit, and then have this function, by my own test, basically the market browser can be very good support, cool?


If you're using jquery, it's easier.

The code is as follows Copy Code

$ ("body"). Bind (' KeyUp ', function (event) {
if (event.keycode==13) {
Document.form.submit ();
}
});


$ (' body ') is the time to indicate where the focus is, Ctrl + Eenter submitting the form is useful
. KeyPress () is the binding key press event
if (e.ctrlkey && E.which = | | e.which = 10) This is very simple, is to detect you are not pressed Ctrl and enter (E.which = = 13 Keyboard area return, E.which = = 10 keypad area back Car
$ (' #submit '). Click (); Press the button

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.