subli快速度创建html,JS插件——自定义下拉框
;(function($,window,document,undefined){
/* *定义Select构造函数 */
var Select=function(ele,opt){
this.$element=ele,
this.defaults={
Items:undefined,//下拉框绑定的数据源 Key Value对象
SelectedValue:undefined,
SelectedValueName:undefined,
SelectedLevel:undefined,
SelectChanged:undefined
},
this.options=$.extend({},this.defaults,opt)
}
Select.prototype={
//初始化
init:function(){
var $this=this;
if($this.SelectedValue==null
||$this.SelectedValue==undefined)
$this.SelectedValue="";
$this.$element.attr("data-role","select");
$this.BindHideEvent();
if($this.$element.parent().children('ul[data-sub-select-for="'+$this.$element.attr('data-id')+'"]').length<1){
$('
.css({'overflow-y:':'auto'})
.attr('data-id','content'+$this.$element.attr('data-id'));
}else{
$this.$element.parent().children('ul[data-sub-select-for="'+$this.$element.attr('data-id')+'"]')
.css({'overflow-y:':'auto'})
.attr('data-id','content'+$this.$element.attr('data-id'));
}
return this.$element.each(function(){
var $select=$(this);
$this.BindItems($select);
$this.InitShowEvent($select);
$select=null;
});
},
BindItems:function($select){
var $this=this;
var $ul=$select.find("ul.sub:first");
$select.attr("data-selected-value","");
$ul.empty()
.width($this.$element.width())
.css({'overflow-y:':'auto'})
.attr('data-id','content'+$this.$element.attr('data-id'));
var items=$this.options.Items;
if(items==undefined||items==null||items.length<1)return;
for(var i=0;i
var data=items[i];
var $li=$("
");
$li.attr("data-id",data.Id);
$li.attr("data-level",0);
$li.attr("title",data.Name);
$li.attr("data-children",JSON.stringify(data.Children));
if(data.Children!=null&&data.Children.length>0){
$li.html(" "+data.Name+"");
}
else{
$li.html(""+data.Name+"");
}
$ul.append($li);
$li.unbind("mousedown").mousedown(function(){
$this.HideUL();
$this.$element.attr("data-selected-level",$(this).attr("data-level"));
$this.$element.attr("data-selected-value",$(this).attr("data-id")).find("li>span>.text-top").text($(this).find(".text").text());
$this.RaiseSelectChanged($(this).attr("data-level"),$(this).attr("data-id"));
});
if(data.Children!=null&&data.Children.length>0){
$li.unbind("mouseenter").mouseenter(function(){
var offset=$(this).offset();
var $ul2=$this.$element.parent().children('ul[data-sub-select-for="'+$this.$element.attr('data-id')+'"]:first').empty();
var list=JSON.parse($(this).attr("data-children"));
if(list==null)return;
for(var j=0;j
{
var data2=list[j];
var $li2=$("
");
$li2.attr("data-id",data2.Id);
$li2.attr("data-level",1);
$li2.attr("title",data2.Name);
$li2.html(""+data2.Name+"");
$ul2.append($li2);
$li2.unbind("mousedown").mousedown(function(){
$this.HideUL();
$this.$element.attr("data-selected-level",$(this).attr("data-level"));
$this.$element.attr("data-selected-value",$(this).attr("data-id")).find("li>span>.text-top").text($(this).find(".text").text());
$this.RaiseSelectChanged($(this).attr("data-level"),$(this).attr("data-id"));
});
$li2=null;
data2=null;
}
list=null;
if($ul2.height()>$(window).height()-20){
$ul2.height($(window).height()-20);
}
if(offset.top+$ul2.height()>$(window).height()){
$ul2.css({left:(offset.left+$ul.width()-25)+'px',top: 20+'px' }).show();
}else{
$ul2.css({left:(offset.left+$ul.width()-25)+'px',top: offset.top+'px' }).show();
}
$ul2=null;
});
}else{
$li.unbind("mouseenter").mouseenter(function(){
$this.$element.parent().children('ul[data-sub-select-for="'+$this.$element.attr('data-id')+'"]:first').hide();
});
}
data=null;
$li=null;
}
if($this.SelectedValue==undefined||$this.SelectedValue==null||$this.SelectedValue.length<1){
$select.attr("data-selected-level","0");
$select.attr("data-selected-value",items[0].Id).find("li>span>.text-top").text(items[0].Name);
}else{
$select.attr("data-selected-level",$this.SelectedLevel);
$select.attr("data-selected-value",$this.SelectedValue).find("li>span>.text-top").text($this.SelectedValueName);
}
$this.options.Items=null;
},
//初始化显示事件
InitShowEvent:function($select){
var $this=this;
$select.find("li>span[data-role=\"select-able\"]").unbind("click").click(function(e){
if($select.hasClass("off")){
var offset=$select.offset();
var $ul=$select.find("ul.sub:first");
if(offset.top+$select.height()+$ul.height()>$(document).height()-offset.top-$select.height()-20){
$ul.height($(document).height()-offset.top-$select.height()-20);
}
$ul=null;
$select.find("ul.sub").css({ left: offset.left, top: offset.top+$select.height() });
$select.removeClass("off");
}else{
$this.HideUL();
}
e.stopPropagation();
});
},
//绑定隐藏事件
BindHideEvent:function(){
var $this=this;
if(typeof($this.$element.attr("data-id"))=="undefined"){
$this.$element.attr("data-id",$this.guid());
}
if(typeof($(document).attr('select_'+$this.$element.attr('data-id')))=="undefined"){
$(document).attr('select_'+$this.$element.attr('data-id'),'');
$(document).bind("mousedown",function(event){
var node = event.target;
if(typeof($(node).attr('data-id'))!='undefined'){
if($(node).attr('data-id')=='content'+$this.$element.attr('data-id')){
event.stopPropagation();
return;
}
}
$this.HideUL();
});
}
},
//隐藏
HideUL:function(){
var $this=this;
$this.$element.removeClass("off").addClass("off").parent().children('ul[data-sub-select-for="'+$this.$element.attr('data-id')+'"]').eq(0).empty().hide();
},
//选中的值修改时触发
RaiseSelectChanged:function(level,selectedValue){
if(this.options.SelectChanged==undefined||this.options.SelectChanged==null)return;
this.options.SelectChanged(level,selectedValue);
return;
}
}
/* *封装为Select插件 */
$.fn.select=function(options){
//创建Beautifier的实体
var obj = new Select(this, options);
//调用其方法
return obj.init();
};
/* *获取下拉框选中的值 */
$.fn.selectedValue=function(){
return this.attr("data-selected-value");
};
})(jQuery,window,document);
subli快速度创建html,JS插件——自定义下拉框相关推荐
- IE6下使用jquery.bgiframe.js插件解决下拉框覆盖浮动层、Dialog的问题
IE6下使用jquery.bgiframe.js插件解决下拉框覆盖浮动层.Dialog的问题 参考文章: (1)IE6下使用jquery.bgiframe.js插件解决下拉框覆盖浮动层.Dialog的 ...
- Combo( 自定义下拉框) 组件
本节课重点了解 EasyUI 中 Combo(自定义下拉框)组件的使用方法,这个组件依赖于 ValidateBox(验证框)组件 一. 加载方式 自定义下拉框不能通过标签的方式进行创建. <in ...
- select美化自定义下拉框样式
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- jquery美化select,自定义下拉框样式
select默认的样式比较丑,有些应用需要美化select,在网上找到一个很好的美化样式效果,本人很喜欢,在这里分享一下. <!DOCTYPE html PUBLIC "-//W3C/ ...
- PYTHON SELENIUM运用execute_script(JS)选择页面下拉框在输入框输入值
By Mejias 网上有很多教程使用SELENIUM去操作页面下拉框并选中,比如Select(web element).select_by_value(option).也有使用selenium对输入 ...
- 【EasyUI篇】Combo自定义下拉框组件
微信公众号:程序yuan 关注可了解更多的教程.问题或建议,请公众号留言; 查看--> 全套EasyUI示例目录 20.Combo自定义下拉框组件 这组件不可以通过class方式进行定义 JSP ...
- uniapp 自定义下拉框
uniapp 自定义下拉框 根据 https://gitee.com/kcren/uniapp-dropdown-filter/tree/master 自己加了一层封装 可以进行切换选择下拉内容 模板 ...
- 文本域 自定义下拉框 支持模糊检索 关键字高亮 上下选择
转载自:文本域 自定义下拉框 支持模糊检索 关键字高亮 上下选择 一.需求 需要创建一个常见问题库,填写存在问题时可以下拉选择,可以模糊搜索,也可以手写.如果选择了问题库中的内容,自动填充内容到存在问 ...
- 下拉框选中状态html,js中select下拉框选中
怎么用js动态 设置select中的某个值为选中值 select 中的某个options为新建,但在子页面新建一个选项时怎么能提交新用JS动态设置select的方法如下: 手动通过原生JS来实现: / ...
- 使用HTML5和JS实现日期下拉框功能
使用HTML5和JS实现日期下拉框功能 如图所示: 代码如下: <center><span style="font-size:26pt;color:red;"&g ...
最新文章
- 获国家杰青的北大教授,被985本科生嫌弃本科学校太差!被网友怒怼!
- Facebook万字长文:AI模型全部迁移至PyTorch框架
- python 字符串转字节数组
- PHP安装zip拓展,以及libzip安装问题
- c语言中式如何定义变量,“新中式”住宅该怎样定义?这场跨界对话给你看建发的答案...
- .NET Core容器化@Docker
- VS 2013 C++ 类模板定义与实现 进行分离
- ASP.NET Core 运行原理解剖[4]:进入HttpContext的世界
- nuxt.js的核心代码_Nuxt.js中的通用应用程序代码结构
- IOS 开发中 Whose view is not in the window hierarchy 错误的解决办法
- python的变量对大小写并不敏感_Python编程基础02:Python基本语法
- position属性absolute(绝对定位),relatve(相对定位)
- 软件portable
- 给妹子讲python-S01E01好用的列表
- otdr测试波形修改软件,AQ7932(OTDR仿真分析软件)
- JQuery----倒计时插件downCount
- GET请求淘宝H5页面获取商品信息
- 实战 | 用 Python 选股票,据说可以多挣个20%
- css设置全局内边距为0,重置CSS - 将填充和边距设置为0?
- watch 和mounted 执行顺序