DOM 对元素添加属性 setAttribute

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script>
			window.onload = function(){
				var oInp = document.getElementById("inp");
				var oBtn = document.getElementById("btn");
				
				oBtn.onclick = function(){
//					oInp.value = "123123";//用点来实现
//					oInp['value'] = "123213";//用中括号 里面是字符串
					
					oInp.setAttribute('value',"123123");
				}
			}
		</script>
	</head>
	<body>
		<input type="text"  id="inp"/>
		<button id="btn">按钮</button>
	</body>
</html>

  

posted @ 2016-03-11 21:26  mingjixiaohui  阅读(725)  评论(0编辑  收藏  举报