JavaScript disables input by Preventdefault () Input[type=text] but retains the cursor

Source: Internet
Author: User

I. Description

Cancels the default action for the event.

This method notifies the Web browser not to perform the default action associated with the event (if such an action exists). For example, if the type attribute is "submit", any event handle can be called at any stage of event propagation, and by calling the method, you can prevent the form from being submitted. Note that if the Cancelable property of the Event object is Fasle, there is no default action, or the default action cannot be blocked. In either case, calling the method has no effect.

Second, the grammar
Event.preventdefault ()
Iii. Example 3.1 block <a> element jump
<a href= "Http://www.mazey.net/baby/blog" target= "_blank" id= "a-prevent" > click I see will not jump </a><script>    document.getElementById (' a-prevent '). AddEventListener (' click ', Function (e) {var eObj = e | | window.event; Eobj.preventdefault ();}); </script>

Click I see will not jump

3.2 Disable <input> element keyboard input
<input type= "text" id= "input-prevent" placeholder= "try to enter"/><script>document.getelementbyid ('    Input-prevent '). AddEventListener (' KeyPress ', function (e) {var eObj = e | | window.event; Eobj.preventdefault ();}); </script>

JavaScript disables input by Preventdefault () Input[type=text] but retains the cursor

This article from "Do not know not to ask" blog, please be sure to keep this source http://mazey.blog.51cto.com/12997993/1946864

JavaScript disables input by Preventdefault () Input[type=text] but retains the cursor

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.