当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JQuery CSS样式控制 学习笔记

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 JQuery CSS样式控制 学习笔记


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 454 ::
收藏到网摘: n/a

本章内容比较简单,所以说明也比较少,有疑问也以跟帖或私聊 测试代码如下
复制代码 代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.test1{
color:#0C9;}
.test2{
color:red;}
</style>
<script src="js/jquery-1.3.2.js">
</script>
<script type="text/javascript">
$(function(){
var count = 2;
$("#aAdd").click(function(){
$( "#testDIV").addClass("test1");
})
$("#aRemove").click(function(){
$( "#testDIV").removeClass("test1");
})
$("#aToggle1").click(function(){
$( "#testDIV").toggleClass("test2");
})
$("#aToggle2").click(function(){
$( "#testDIV").toggleClass("test2",count++ % 3 == 0 );
})
$("#aCSS1").click(function(){
$("#testDIV").css({background:"red"}).css("color","white");
})
})
</script>
</head>
<body>
<div id="testDIV" >我会变颜色哦</div>
<a href="#" id="aAdd">添样式</a>
<a href="#" id="aRemove">去除样式</a>
<a href="#" id="aToggle1">变样式</a>
<a href="#" id="aToggle2">多点几下变样式</a>
<a href="#" id="aCSS1">变色</a>
</body>
</html>

1.addClass(class)
描述:为选择的元素集合添加指定样式。
2.removeClass([class])
描述:为选择的元素集合删除指定样式。
3.toggleClass(class)
描述:替换选择的元素集合样式。备注下,如果当前元素的样子已经为class时,将会去除该样式,相当于addClass与removeClass的结合方法。
4.toggleClass(class, switch)
描述:与上一个方法类似,区别就是多加了个switch判断,当switch值为true时,对进行样式的改变
5.css(styleName,value)/css(styleName)/css({value})
描述:css(styleName,value)用于设置当前元素的styleName样式属性值为value,css(styleName)用于获取当前元素的styleName样式属性值,而css({value})而为另一种设置样式属性值的方法,具体用法参考例子^^,因为跟element.attr的用法类似所以在这就不详细说明了