Summary of Javascript development knowledge

Source: Internet
Author: User

1. TextBox verification is actually a regular content)

<! -- Use a regular expression to restrict Chinese characters only --> <input type = "text" onkeyup = "value = value. replace (/[^ \ u4E00-\ u9FA5]/g, '')" onbeforepa
Ste = "clipboardData. setData ('text', clipboardData. getData ('text'). replace (/[^ \ u4E00-\ u9F
A5]/g, '')"/>
<! -- Use a regular expression to limit that only numbers can be entered --> <input type = "text" onkeyup = "value = value. replace ([^ \ d]/g, '')" onbeforepaste = "clipboar
DData. setData ('text', clipboardData. getData ('text'). replace (/[^ \ d]/g, '')"/>
<! -- Use a regular expression to limit that only numbers and English characters can be entered --> <input type = "text" onkeyup = "value = value. replace ([\ W]/g, '')" onbeforepaste = "clipboar
DData. setData ('text', clipboardData. getData ('text'). replace (/[^ \ d]/g, '')"/>
<! -- Certificate number and small data point --> <input type = "text" ID = "Text1" onkeyup = "value = value. replace (/[^ \ d | ^ \.] /g, '')" o
Nbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text'). replace (/[^ \ d |
^ \.] /G, '')"> // remove space function trim (str) {return str. replace (/(^ \ s *) | (\ s * $)/g ,"");}

The onbeforepaste attribute prevents copying and pasting.

//validate emailfunction IsMail(mail) {     var patrn = /^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$/;     return patrn.test(mail);}//validate urlfunction IsURL(url){     var regexp = /^http://[A-Za-z0-9]+.[A-Za-z0-9]+[/=?%-&_~`@[]':+!]*([^<>""])*$/;     return regexp.test(url);} 

2. Check whether CheckBoxList is selected.

// Id is the ID of the CheckBoxList control. // return true indicates that function checkLocCate (id) {var status = true; var inputs = document is not selected. getElementById (id ). getElementsByTagName ("input"); for (var I = 0; I
     

3. Add items for DropDownList

// Id is the IDfunction addOptions (id) {var ddl = document. getElementById (id); // clears the content of the DropDownList ddl. options. length = 0; for (var I = 0; I <10; I ++) {// Options the first parameter is the Text Value, and the second parameter is the Value ddl. add (new Option (I, I ));}}

4. Add rows and columns to the table

Adding rows and columns in javascript is implemented through insertRow and inertCell. See the following example.

<Html xmlns = "http://www.w3.org/1999/xhtml"> 

5. Differences between setTimeOut and setInterval in javascript

// Execute the handler function 1window. setInterval ("function 1", 1000) in one second; // delay 1 second to execute function 2window. setTiemout ("function 2", 1000 );

6. js get the string length

var str= str.replace(/[^\x00-\xff]/g, "**").length;
  1. Javascript object-oriented basics and implementation of interfaces and inheritance classes
  2. Update UpdatePanel using JavaScript
  3. Two common methods for defining classes in JavaScript

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.