var placeholder=document.createELement("img");
placeholder.setAttribute("id","placeholder");
placeholder.setAttribute("src","images/placeholder.gif");
placeholder.setAttribute("alt","my image gallery");
var description=document.createElement("p");
description.setAttribute("id","description");
var desctext=document.createTextNode("choose an image");
description.appendChild(desctext);<img id="placeholder" src="placeholder.gif" alt="my"/>
<p id="description">choose an image</p>
setAttribute属性不是更改现有的属性节点嘛,为什么可以连续创建属性节点,和属性节点中的内容,不是很理解
解决方案 »
- 急急急!!!IE6下无法加载js文件
- 请教:关于页面打印的问题
- JSP 问题
- 如何用js对静态菜单的增加 删除 和修改?
- 在visit下,myeclipse5.5GA咋么不呢运行http://localhost:8080/
- 我想去掉下拉框的按钮,就和input一样,但是要实现和下拉框一样的功能,即点击这个框,即下拉出可选项
- iframe中页面的打印问题
- javascript读ASP的COOKIES(带汉字编码的)问题?急!急!急!急!急!急!急!急!
- 高手啊,,,,怎样去掉网页打印弹出的那个选择打印机界面?
- 请大家帮下忙!!!!!。。。。。
- 弹出层页面传值
- 求一个可以检测JavaScript圈复杂度的工具!!!!!!!
placeholder.setAttribute("id","placeholder");
等于
placeholder.id="placeholder";(id不是自定义属性)
placeholder.setAttribute("cscs","placeholder"); //这句就会错了,系统没有这个属性!
但是如果自己写代码却是正常可以获取!
你试试下面的代码
<!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>无标题文档</title>
<script type="text/javascript">
window.onload=function(){
var placeholder=document.createElement("img");
placeholder.setAttribute("id","placeholder");
placeholder.setAttribute("src","images/placeholder.gif");
placeholder.setAttribute("alt","my image gallery");
var description=document.createElement("p");
description.setAttribute("id","description");
description.setAttribute("newAttr","Iamnewer")
var desctext=document.createTextNode("choose an image");
description.appendChild(desctext);
document.body.appendChild(description);
document.body.appendChild(placeholder);
};
</script>
<style type="text/css">
#div {
width:450px;
height:450px;
}
#div a{
position:absolute;
}
</style>
</head>
<body>
<input type="button" id="test" onclick="alert(document.getElementById('description').getAttribute('newAttr'))" value="test" />
</body>
</html>
var i = [];
i[3] = 5;//此时i.length = 4很容易得到
i["test"] = 3;//i.length=4
i["5"] = 9; //i.length =6
var j = [];
j["test"] = 11;//j.length = 0;同时
var k = {};
k["test"] = 5;//k.length = undefined没什么难理解的
但是值得小心~~~~!
description.setAttribute("newAttr","Iamnewer")也就是说可以自定义任何属性节点名称和属性值????