JS面向对象之多选框实现
前端  /  管理员 发布于 7年前   363
本文实例为大家分享了JS面向对象之多选框实现代码,供大家参考,具体内容如下 描述: JS面向对象――多选框的实现 效果: 实现: Utile.js UIComponent.js html 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。(function () { Object.prototype.addProto=function (sourceObj) { var names=Object.getOwnPropertyNames(sourceObj); for(var i=0;i
var CheckBox=(function () { function CheckBox(parent) { this.checkView=this.init(parent); } /* //ES5 单例 CheckBox.getInstance=function () { if(!CheckBox._instance){ CheckBox._instance=new CheckBox(); } return CheckBox._instance; };*/ CheckBox.prototype.addProto({ _label:"", _checked:false, init:function (parent) { if(this.checkView) return this.checkView; var div=document.createElement("div"); var icon=RES.getImage("f-checkbox"); div.appendChild(icon); var label=document.createElement("span"); div.style.position=icon.style.position=label.style.position="relative"; icon.style.float=label.style.float="left"; label.textContent=""; Object.assign(label.style,{ fontSize:"16px", lineHeight:"20px", marginLeft:"5px", marginRight:"10px" }); var h=RES.getNameXMLData("f-checkbox").h; icon.style.top=(20-h)/2+"px"; div.appendChild(label); parent.appendChild(div); this.clickHandlerBind=this.clickHandler.bind(this); div.addEventListener("click",this.clickHandlerBind); return div; }, clickHandler:function (e) { this.checked=!this.checked; }, set label(value){ this._label=value; this.checkView.lastElementChild.textContent=value; }, get label(){ return this._label; }, set checked(value){ if(this._checked===value)return; this._checked=value; if(value){ RES.changeImg(this.checkView.firstElementChild,"f-checkbox-active"); }else{ RES.changeImg(this.checkView.firstElementChild,"f-checkbox"); } this.checkView.firstElementChild.style.position="relative"; this.dispatchMessage(value); }, dispatchMessage:function (value) { var evt=new Event("change"); evt.checked=value; evt.elem=this; document.dispatchEvent(evt); }, get checked(){ return this._checked; } }); return CheckBox;})(); var Radio=(function () { function Radio(parent,groupName) { this.constructor.supClass.constructor.call(this,parent); this.groupName=groupName; this.checkView.self=this; this.checkView.setAttribute("groupName",groupName); } Radio.extendClass(CheckBox); Radio.prototype.addProto({ clickHandler:function (e) { // console.log(Model.instance.menuData); if(this.checked)return; var list=document.querySelectorAll("[groupName="+this.groupName+"]"); for(var i=0;i
您可能感兴趣的文章:
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号