编程语言
首页 > 编程语言> > javascript事件与业务逻辑之间的桥接

javascript事件与业务逻辑之间的桥接

作者:互联网

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
		#menu_list{
			width: 400px;
			height: 50px;
			margin: 0 auto;
			border: 1px solid red;
		}
		#menu_list .box{
			list-style-type: none;
			width: 100%;
			height: 100%;
			margin:0px;
			padding: 0px;
		}
		#menu_list .box .box_list{
			float: left;
			width: 80px;
			height: 50px;
			text-align: center;
			line-height: 50px;
		}
		</style>
	</head>
	<body>
		<div id="menu_list"></div>
		<script language="JavaScript" src="myselftool.js"></script>
		<script language="JavaScript">
			function createLi(){
				var txt=['用户名','等级','消息','金币','会员'];
				var conaintor=Ming.dom.getId('menu_list');
				var ul=Ming.dom.createDom('ul');
				ul.className="box";
				for(var i=0;i<5;i++){
					var li=Ming.dom.createDom('li');
					li.className="box_list";
					li.appendChild(document.createTextNode(txt[i]));
					ul.appendChild(li);
				}
				conaintor.appendChild(ul);
			}
			createLi();
			//提取事件的共同点
			function changeColor(dom,obj,bg){
				dom.style.color=obj.color;
				dom.style.fontSize=obj.fontsize;
				dom.style.background=bg;
			}
			var li_list=Ming.dom.getTag('li');
			var obj={color:'red',fontsize:'16px'};
			var obj2={color:'#000',fontsize:'14px'};
			for(var j=0;j<li_list.length;j++){
				Ming.eventUtil.addHandler(li_list[j],'mouseover',function(){
					//进行事件与业务之间的桥接,this回调事件元素
					changeColor(this,obj,'#fff');
				});
				Ming.eventUtil.addHandler(li_list[j],'mouseout',function(){
					changeColor(this,obj2,'#fff');
				});
			}
		</script>
	</body>
</html>

标签:box,逻辑,dom,桥接,javascript,list,li,var,Ming
来源: https://blog.csdn.net/cdcdhj/article/details/119360147