当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JQuery 学习笔记 element属性控制

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 学习笔记 element属性控制


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

JQuery元素属性控制
复制代码 代码如下:

<!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" />
<script src="js/jquery-1.3.2.js" ></script>
<script type="text/javascript"><!--
$(function(){
$("#aAttr1").click(function(){
$( ":text").attr("value",$("#divTest").attr("id"));
})
$("#aAttr2").click(function(){
$( ":text").attr("value",function(){
return $("#divTest").attr("id");
});
})
$("#aAttr3").click(function(){
$( ":text").attr({value:"test2"});
})
$("#aAttr4").click(function(){
$("#inputTest2").removeAttr("value");
})
})
// --></script>
<title>无标题文档</title>
</head>
<body>
<form>
<input id="inputTest1" type="text" />
<input id="inputTest2" type="text" value="test" />
<div id="divTest">123</div>
<a href="#" id="aAttr1">在text表单中显示DIV的ID方法1</a>|
<a href="#" id="aAttr2">在text表单中显示DIV的ID方法2</a>|
<a href="#" id="aAttr3">在text表单中显示test2</a>|
<a href="#" id="aAttr4">去除inputTest2的value属性</a>|
<input type="reset" />
</form>
</body>
</html>

1.element.attr(name)
描述:用于获取某个元素的name属性值,如例子中 $("#divTest").attr("id")就可获取divTest的ID值。
2.element.attr(name,value)
描述:用于设置某个元素的name属性值,如例子中$(":text").attr("value",$("#divTest").attr("id"))就将divTest的ID值赋于text表单的value值。
注:例子中(":text")用于获取input表单type为text的元素,同样其它表单也可用同样的方法获取,如<input type="button"/>即可用$(":button")进行获取,其返回值为Array(Element),也可用$(":input")获取所有的input元素。。在JQuery中要获取和设置元素的text与value值还可以使用element.text()/element.text(value)、element.val()/element.val(Value),用法与element.html()一样,若有疑问可以跟帖,我再做说明
3.element.attr(name,function)
描述:用于设置某个元素的name属性值与上一个类似,只是这里的value可以写成个function,更为灵活。
4.element.remove(name);
描述:用于删除某个元素的name属性。