摘要:<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>jQuery練習</title> <style> .dex { font-size:35px; color:cornflowerblue;
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>jQuery練習</title> <style> .dex { font-size:35px; color:cornflowerblue; } </style> <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ // $("p").addClass("dex"); $(":text").val("HelloMS"); // $("p").toggleClass("dex"); }); }); </script> </head> <body> <!--addClass() 元素添加指定的類名--> <h1>我是H1</h1> <p>我是P</p> <button>點擊添加</button> <!--attr()設(shè)置或返回匹配元素的屬性和值 hasClass()檢查匹配的元素是否擁有指定的類 html()設(shè)置或返回匹配的元素集合中的 HTML 內(nèi)容innerHTML removeAttr()從所有匹配的元素中移除指定的屬性 removeClass()匹配的元素中刪除全部或者指定的類--> <!-- toggleClass()匹配的元素中添加或刪除--> <!--val()設(shè)置或返回匹配元素的值比如value值--> <p>姓名:<input type="text" name="Name" value="Hello Suo" /></p> <button>點擊我</button> </body> </html>