JavaScript advanced Programming-form scripting

Source: Internet
Author: User

1. Submitting the formSubmitonsubmit  2. Change event for the formThe change event of the input and textarea elements is triggered when they lose focus and value changesThe Change event for select Occurs when the option changes  3. Select the text Select () and get the selected textall text is selected by default when the text box has the focus to improve the user experience.
if (window.getselection) {// Modern Browser userselection=window.getselection ();    } ElseIf (document.selection) {//IE browser considering opera, should be placed in the back Userselection=document.selection.createrange ();    }

Of course jquery objects also have a select () method. replication method for jquery clone ().  An example:
<!DOCTYPE HTML><HTML><HeadLang= "en">    <MetaCharSet= "UTF-8">    <title></title>    <Scriptsrc= "Jquery-1.11.3.js"></Script></Head><Body><DivID= "AA"><inputtype= "text"style= "width:100px;height:30px;"value="" /><inputtype= "text"style= "width:100px;height:30px;"value="" /></Div></Body><Script>$ (document). Ready (function(){$("input"). Click (function(){//$ ("input") [0] This means that the jquery object is transformed into a DOM object$( This). Select ();if(window.getselection) {//Modern Browsersuserselection=window.getselection (); } Else if(document.selection) {//IE browser considering opera, should be put in the backuserselection=Document.selection.createRange (); } console.log (userselection);//a HtmlElement object is defined in the DOM Level2 standard, which specifies that all DOM objects are instances of HtmlElement.//so we can use this to determine if an object is a DOM object: If the object is an instance of HtmlElement,//then it must be a DOM object. In browsers that do not support htmlelement, we still use feature detection. /*if ($ (this) instanceof JQuery) {alert ("Jqueryduixiang")}else if (Document.getelementsbytag Name ("input") [0] instanceof HtmlElement) {alert ("DOM")}*/return false;//Prevent bubbling})$("#AA"). Click (function() {alert ("AA")})    })</Script></HTML>

  4. Accessing the Clipboard data ClipboarddataThere are three methods: GetData (), SetData (), ClearData ()  5. Automatically switch focusThe next input automatically gets the focus when it reaches a certain length  Fancy gameplay for 6.<select> and <option>Add (newoption,reloption); Insert an element into the controlmultiple: Multiple selectionoptions: Htmlcollection of all <option> elementsRemove (Index): Removes the option for a given positionSelectedIndexSize: Number of rows visible in the selection box You can use:
var newoption=new option ("option text", "option value"); Selectbox.appendchild (newoption);
Add an option  7.appendChild ()can be used to move items in one list to another list finally, note that the move ~Example:
<Body> <ulID= "MyList1"><Li>Coffee</Li><Li>Tea</Li></ul><ulID= "MyList2"><Li>Water</Li><Li>Milk</Li></ul> <PID= "Demo">Please click the button to move the item from one list to another.</P> <Buttononclick= "myFunction ()">Try it yourself.</Button> <Script>functionmyFunction () {varnode=document.getElementById ("MyList2"). Lastchild;document.getelementbyid ("MyList1"). appendchild (node);}</Script>
 What we thought might be: remove water from the second item, and then generate a text water to append to. However, it is not necessary to just appendchild (), it will naturally remove the water from two items and add it to an item. the same is true of the append effect in jquery.       

JavaScript advanced Programming-form scripting

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.