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; |
- Javascript object-oriented basics and implementation of interfaces and inheritance classes
- Update UpdatePanel using JavaScript
- Two common methods for defining classes in JavaScript