属性节点:
某一指定的元素节点的属性。
代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>JavaScript</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
window.onload = function(){
//获取节点
var NameNode = document.getElementById("name");
//读取节点属性值
alert(NameNode.value);
//重写属性值
NameNode.value ="Mike";
}
</script>
</head>
<body>
<p>你喜欢哪个城市</p>
<ul id="City">
<li id="bj" name="beijing">北京</li>
<li id="Sh">上海</li>
<li>广州</li>
<li>深圳</li>
</ul>
<br/>
<p>你喜欢哪款单机游戏</p>
<ul id="game">
<li>反恐精英</li>
<li>魔兽</li>
<li>红警</li>
<li>实况</li>
</ul>
<br/>
<br/>
Name:<input id="name" type="text" name="username" value="LoveCoffee"/>
</body>
</html>说明:
操作属性的一般步骤:
1.获得节点(根据获取元素节点的函数获取)
2.读取属性值
3.重写属性值
本文出自 “爱咖啡” 博客,请务必保留此出处http://4837471.blog.51cto.com/4827471/1569143
原文地址:http://4837471.blog.51cto.com/4827471/1569143