jQuery常用樣式操作實例分析(獲取、設(shè)置、追加、刪除、判斷等)
本文實例分析了jQuery常用樣式操作。分享給大家供大家參考,具體如下:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css"> .high { font-weight: bold; /* 粗體字 */ color : red; /* 字體顏色設(shè)置紅色*/ } .another { font-style: italic; color: blue; } </style> <script src="js/jquery-1.10.1.min.js" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ $(function(){ //獲取樣式 $("input:eq(0)").click(function(){ alert( $("p").attr("class") ); }); //設(shè)置樣式 $("input:eq(1)").click(function(){ $("p").attr("class","high"); }); //追加樣式 $("input:eq(2)").click(function(){ $("p").addClass("another"); }); //刪除全部樣式 $("input:eq(3)").click(function(){ $("p").removeClass(); }); //刪除指定樣式 $("input:eq(4)").click(function(){ $("p").removeClass("high"); }); //重復(fù)切換樣式 $("input:eq(5)").click(function(){ $("p").toggleClass("another"); }); //判斷元素是否含有某樣式 $("input:eq(6)").click(function(){ alert( $("p").hasClass("another") ) alert( $("p").is(".another") ) }); }); //]]> </script> </head> <body> <input type="button" value="輸出class類"/> <input type="button" value="設(shè)置class類"/> <input type="button" value="追加class類"/> <input type="button" value="刪除全部class類"/> <input type="button" value="刪除指定class類"/> <input type="button" value="重復(fù)切換class類"/> <input type="button" value="判斷元素是否含有某個class類"/> <p class="myClass" title="選擇你最喜歡的水果." >你最喜歡的水果是?</p> <ul> <li title='蘋果'>蘋果</li> <li title='橘子'>橘子</li> <li title='菠蘿'>菠蘿</li> </ul> </body> </html>
效果圖:
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jquery中Ajax用法總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計有所幫助。
相關(guān)文章
jQuery彈出層插件popShow(改進(jìn)版)用法示例
這篇文章主要介紹了jQuery彈出層插件popShow(改進(jìn)版)用法,對比前文分析了popShow插件的使用方法,需要的朋友可以參考下2017-01-01jquery插件jquery.dragscale.js實現(xiàn)拖拽改變元素大小的方法(附demo源碼下載)
這篇文章主要介紹了jquery插件jquery.dragscale.js實現(xiàn)拖拽改變元素大小的方法,涉及jquery針對鼠標(biāo)事件的響應(yīng)及頁面元素動態(tài)操作的相關(guān)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2016-02-02使用jQuery模板來展現(xiàn)json數(shù)據(jù)的代碼
通常我們在使用ajax的時候,都避免不了和json這種輕巧的數(shù)據(jù)格式打交道。可是往往手動的去解析json,構(gòu)建HTML,比較麻煩。現(xiàn)在有了這個插件,就能像Extjs那樣使用模板解析json了。2010-10-10基于jquery的關(guān)于動態(tài)創(chuàng)建DOM元素的問題
在我們實際的項目之中,相信有很多的朋友直接使用了以下的格式創(chuàng)建DOM元素。2010-12-12