setAttribute

来源:互联网 发布:Javascript算法 编辑:程序博客网 时间:2024/04/30 10:14
<!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=gb2312">
<title>setAttribute 测试</title>
<script language="javascript" type="text/javascript">
<!--

function init() {
    
var obj = document.getElementById("btn");
    obj.onclick
=changeValue;
       //改变样式IE 不支持class   obj.
className="style1";    
       //
    obj.style.background="#CC6600";
}

function changeValue() {
    document.getElementById(
"txt").value = "New value!";
}

-->
</script>
</head>
<body onload="init();">
<input name="btn" type="button" id="btn" value="Click" />
<input name="txt" type="text" id="txt" value="" />
</body>
</html>