jquery 样式 css
2013-10-23 15:04
351 查看
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>dom节点练习和样式练习</title> <script type="text/javascript" src="/TestJquery/jq/jquery-1.3.2.js"></script> <script type="text/javascript" src="/TestJquery/js/dom.js"></script> <style> .high{ font-weight: bold;/*粗体字*/ color : red; /*红色字体*/ } .another{ font-style: italic;/*斜体*/ color:blue; /*蓝色字体*/ } </style> </head> <body> <input id="one" type="button" value="输出class类"/> <input id="two" type="button" value="设置class类"/> <input id="three" type="button" value="追加class类"/> <input id="four" type="button" value="删除全部class类"/> <input id="five" type="button" value="删除指定class类"/> <input id="sex" type="button" value="重置切换class类"/> <p title="选择你最喜欢的水果">选择你最喜欢的水果?</p> <ul> <li title="苹果">苹果</li> <li title="橘子">橘子</li> <li title="菠萝">菠萝</li> </ul> </body> <script type="text/javascript"> $(document).ready(function(){ var $para = $('p');//获取<p>节点 var p_txt = $para.attr('title');//获得<p>元素节点属性title //alert(p_txt); $('p').attr("title","改变了title的值");//设置单个的属性值 $('p').attr({"title":"改变了title的值","name":"tName"});//一次性的为同个元素设置多个属性 $('p').removeAttr("title");//删除<p>元素的属性title //追加样式 $('#two').click(function(){ //给<p>设置个class属性 class="high" $('p').attr("class","high"); }); $('#three').click(function(){ //给<p>追加个class样式 class="high another" (在原有的样式上追加新样式,原来的不变。) $('p').addClass('another'); }); /*在CSS中以下两条规定 * 1:如果给一个元素添加了多个class值,那么就相当于合并了它们的样式。 * 2:如果有不同的class设定了同一个样式属性,则后者覆盖前者。 * 本例中 字体的颜色就是这种情况哦 * */ //移除样式 $('#five').click(function(){ $('p').removeClass("another");//移除制定样式 }); //如果移除多个样式 $('p').removeClass("another").removeClass("high"); 这种写法等同于 $('p').removeClass("another high"); $('#four').click(function(){//移除所有样式 $('p').removeClass(); }); //切换样式 $('#sex').click(function(){ //如果存在改样式那么就删除它,如果不存在那么就追加上,从而实现样式的切换。 $('p').toggleClass("another"); }); //判断是否含有某个样式 $('p').hasClass("another");//如果有返回true 如果没有返回false /* * 味蕾增强代码的可读性jquery提供了一个等价的方法 * $('p').is('.another'); * */ }); </script> </html>
本文出自 “小浩” 博客,请务必保留此出处http://zhangchi.blog.51cto.com/5214280/1215853
相关文章推荐
- jquery中css的样式
- jQuery的属性与样式之样式操作.css()
- jquery样式jquery.css()方法
- JQuery操作属性、样式、风格(attr、class、css)
- Jquery中.css()与.addClass()两种方法设置样式的区别
- jquery样式jquery.css()方法
- js获取和设置DOM样式函数cssStyle(类似于jquery的$(elem).css())
- 如何利用 jQuery 修改 css 中带有 !important 的样式属性?
- js随笔,css和js禁止网页选择文本,table的class样式使得td的class样式失效,jquery获得元素坐标
- JQuery巧妙利用CSS操作打印样式
- jQuery的属性与样式之样式操作.css()
- jQuery的属性与样式之.css()与.addClass()设置样式的区别
- jquery样式jquery.css()方法
- 使用jquery+CSS实现控制打印样式
- jquery样式操作方法css
- jQuery通过CSS()方法给指定的元素同时设置多个样式
- JQuery学习笔记8:JQuery之CSS样式控制
- 【转】jQuery源码分析-13 CSS操作-CSS-类样式-addClass+removeClass+toggleClass+hasClass
- jquery样式jquery.css()方法
- css和jQuery ,字符串中重新定义单个字符样式背景