<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/> <title>Test</title> <script type= "Text/javascript" language= "JavaScript" src= "Jquery.js" ></script> <script type= "Text/javascript" language= "JavaScript" > function Validata () { if ($ ("#username"). val () = "") { document.write ("Please enter first name"); return false; } if ($ ("#password"). val () = "") { document.write ("Please enter the password"); return false; } if ($ ("#telephone"). val () = "") { document.write ("Please enter the telephone number"); } if ($ ("#email"). val () = "") { $ ("#email"). Val ("shuangping@163.com"); } }
function Isinteger (obj) {
reg=/^[-+]?d+$/; if (!reg.test (obj)) { $ ("#test"). HTML ("<b>please input correct figures</b>"); }else{ $ ("#test"). HTML (""); } } function Isemail (obj) { reg=/^w{3,}@w+ (. w+) +$/; if (!reg.test (obj)) { $ ("#test"). HTML ("<b> Please enter the correct email address </b>"); }else{ $ ("#test"). HTML (""); } } function isstring (obj) { reg=/^[a-z,a-z]+$/; if (!reg.test (obj)) { $ ("#test"). HTML ("<b> can only enter characters </b>"); }else{ $ ("#test"). HTML (""); } } function Istelephone (obj) { reg=/^ (d{3,4}-)? [1-9]d{6,7}$/; if (!reg.test (obj)) { $ ("#test"). HTML ("<b> Please enter the correct phone number!") </b> "); }else{ $ ("#test"). HTML (""); } } function IsMobile (obj) { reg=/^ (+d{2,3}-) d{11}$/; if (!reg.test (obj)) { $ ("#test"). HTML ("Please enter the correct mobile phone"); }else{ $ ("#test"). HTML (""); } } function Isuri (obj) { reg=/^http://[a-za-z0-9]+. [a-za-z0-9]+[/=?%-&_~ ' @[] ': +!] * ([^<> ""]) *$/; if (!reg.test (obj)) { $ ("#test"). HTML ($ ("#uri"). Val () + "Please enter the correct inernet address"); }else{ $ ("#test"). HTML (""); } }
Document loading complete execution $ (document). Ready (function () { Do something here
Interlace color function $ ("P"). each (function (i) { this.style.color=[' red ', ' green ', ' blue ', ' black '][i%2] });
EQ (2) gets the 3rd element of the $ ("P") collection $ ("P"). EQ (2). Click (function () {$ ("#display"). CSS ("Color", "Blue")}); All p in test has the style "over" attached. $ ("#test >p"). AddClass ("over");
The last p in test attaches the style "out". $ ("#test p:last"). AddClass ("Out");
Select sibling element Not yet understood $ (' #faq '). Find (' dd '). Hide (). End (). Find (' DT '). Click (Function ()
Select parent Element $ ("a"). Hover ( Function () {$ (this). Parents ("P"). AddClass ("Out")}, Function () {$ (this). Parents ("P"). Removeclass ("Out")})
Hover mouse hover effect, toggle switch the function you want to call every time you click, Trigger (EventType): Triggers a class of events on each matching element. Bind (EVENTTYPE,FN), Unbind (EventType): The binding of an event is bound to delete a binding event from each matching element (added).
Method of ligatures $ ("#display"). Hover (function () { $ (this). addclass ("over"); },function () { $ (this). Removeclass ("over"); }) . Click (function () {Alert ($ ("#display"). Text ())};
if ($.browser.msie) {//Judging browser, if IE performs the following functions
Focus $ ("input[@type =text],textarea,input[@type =password]") . focus (function () {$ (this). CSS ({background: "White", border: "1px solid Blue"})} It can be written in this way, . blur (Function () {$ (this). CSS ({background: ' White ', border: ' 1px solid Black '})}) Lose focus CSS styles can be added by addclass () $ ("input[@type =text],textarea,input[@type =password]") . blur (Function () {$ (this). CSS ({background: ' White ', border: "1px solid Black"}); }
});
</script> <style type= "Text/css" > . over{ Font-size:large; Font-style:italic; } . out{ Font-size:small; } </style>
<body > <div id= "Display" >demo</div> <div id= "Test" > <p>adfa<a>dfasfa</a>sdfasdf</p> <p>adfadfasfasdfasdf</p> <p>adfadfasfasdfasdf</p> <p>adfadfasfasdfasdf</p> </div> <form id= "Theform" > Isstring<div><input type= "text" id= "username" onblur= "isstring (this.value)"/></div> Isinteger<div><input type= "text" id= "password" onblur= "Isinteger (this.value)"/></div> Istelephone<div><input type= "text" id= "Telephone" onblur= "Istelephone (this.value)"/></div> Ismobile<div><input type= "text" id= "mobile" onblur= "IsMobile (this.value)"/></div> Isemail<div><input type= "text" id= "email" onblur= "Isemail (this.value)"/></div> Isuri<div><input type= "text" id= "uri" onblur= "Isuri (this.value)"/></div> <div><input type= "button" value= "Validata" onclick= "return Validata ();" /></div> </form> </body> |