Walk_
<!--
简单的演示
-->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>RunJS</title>
</head>
<body>
<div id="color_button">
<button type="button" value="黑色">黑色</button>
<button type="button" value="白色">白色</button>
<button type="button" value="蓝色">蓝色</button>
</div>
<span id="text"></span>
<script>
var get_button_div=document.getElementById("color_button");
var get_button=document.getElementsByTagName("button");
var get_text=document.getElementById("text");
/*
* @element 需要修改值的元素
* @value 需要修改的值
*/
function add_value(element,value){
element.innerHTML=value;
};
/*
* @element_1 需要绑定事件的元素
* @element_2 需要修改值的元素
*/
function bingding_event(element_1,element_2){
for(var i=0,j=element_1.length;i<j;i++){
(function(i){
element_1[i].onclick = function(){
add_value(element_2,this.value);
}
})(i)
}
};
bingding_event(get_button,get_text);
</script>
</body>
</html>