javascript 获取和设置属性getAttribute setAttribute
来源:互联网 发布:淘宝开店交保证金多少 编辑:程序博客网 时间:2024/04/29 20:15
getAttribute只有一个参数,所查询属性的名字
使用方法:object.getAttribute(attribute);
var pas=document.getElementsByTagName("p");
for(var i=0;i<pas.length;i++){
var titleText=pas[i].getAttribute("title");
if(titleText != null)
{
alert(titleText);}}
//测试结果为:
setAttibute 用法
<script type="text/javascript">
var pas=document.getElementsByTagName("p");
for(var i=0;i<pas.length;i++){
var titleText=pas[i].getAttribute("title");
if(titleText != null)
{
pas[i].setAttribute("title","a new title");
alert(pas[i].getAttribute("title"));
}
}
源代码:
<!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>
</head>
<body>
<p title="this is a story"> 依兰爱情故事</p>
<p > this is only a story</p>
<ol id="feel"></ol>
<li>感人</li>
<li>内涵</li>
<script type="text/javascript">
var pas=document.getElementsByTagName("p");
for(var i=0;i<pas.length;i++){
var titleText=pas[i].getAttribute("title");
if(titleText != null)
{
alert(titleText);
pas[i].setAttribute("title","a new title");
alert(pas[i].getAttribute("title"));
}
}
</script>
</body>
</html>
- javascript 获取和设置属性getAttribute setAttribute
- 获取和设置属性getAttribute、setAttribute
- js 获取和设置 元素 属性 getAttribute setAttribute
- js 中getAttribute和setAttribute属性
- js 中设置或获取自定义属性的方法setAttribute getAttribute attributes
- JS getAttribute和setAttribute(取得和设置属性)的使用介绍
- 设置 取消input的disabled属性 getattribute(),setAttribute(),removeattribute()用法
- getAttribute()方法和setAttribute()
- getAttribute、setAttribute和removeAttribute
- setAttribute和getAttribute
- setAttribute 和 getAttribute区别
- setAttribute 和 getAttribute 的设值和获取方法
- JavaScript DOM getElementByTagName 中关于 getAttribute() 和setAttribute()的使用
- setAttribute和getAttribute的区别
- getAttribute 和setAttribute 的使用方法
- session.setAttribute和session.getAttribute
- 关于getAttribute()和setAttribute()方法
- session.setAttribute()和session.getAttribute()
- linux下卸载自带jdk,重新安装jre运行环境
- 新开技术问题解决博客测试文章
- 学习笔记——处理器管理(2)
- 清除PLSQL Developer访问数据库历史记录
- JavaWeb(四)-----Web 应用程序状态管理
- javascript 获取和设置属性getAttribute setAttribute
- JavaWeb(五)---imgCode
- 树莓派系统、硬件更新
- Array的一些排序算法
- python中datetime中now和utcnow的区别
- 5-1 Insertion or Heap Sort
- 【深入Java虚拟机】之一:Java内存区域与内存溢出
- C语言求杨辉三角的6种方法
- java 单例模式之线程安全的饿汉模式和懒汉模式