当前位置:首页 >> 网络编程

JQuery组件基于Bootstrap的DropDownList(完整版)

在前文 创建基于Bootstrap的下拉菜单的DropDownList的JQuery插件 中,实现了DropDownList的JQuery组件,但是留有遗憾。就是当下拉菜单出现滚动条的时候,滚动条会覆盖菜单右侧的两个圆角。使得下拉菜单左侧有2个圆角,右侧没有,看上去不是很完美。如下图所示:

JQuery组件基于Bootstrap的DropDownList(完整版)

本文的内容就是如何恢复右侧的圆角 

先看看原本的下拉菜单的HTML结构:

 "dropdown-menu dropdown-menu-right" role="menu">
"#">Action</a></li>
"#">Another action</a></li>
"#">Something else here</a></li>
"divider"></li>
"#">Separated link</a></li>
"htmlcode">
"ul[style]")语句来找寻里面的ul标签(因为里面的ul含有style属性,而外面的ul没有)。 

再说说JQuery的height方法。当调用JQuery的height方法来计算隐藏元素高度时,估计是先会显示元素,然后计算高度,再隐藏元素。这会有两个问题。一是显示再隐藏,速度很快,肉眼看不出,但是浏览器不会说谎,有时浏览器会额外显示滚动条。二是如果该元素的父元素也是隐藏的,则height方法会返回0。 

完善版的源代码:

"Q",
"示例",
"<div class='input-group'>";
"<input type='text' class='form-control' name='" + o.InputName + "' id='" + o.InputName + "' />";
"<div class='input-group-btn'>";
"<button type='button' class='btn btn-default dropdown-toggle' data-toggle='dropdown'>" + o.ButtonText + " <span class='caret'></span></button>";
"<ul class='dropdown-menu dropdown-menu-right' role='menu' >";
"<li><ul class='dropdown-menu ' style='display:inherit;position:inherit;top:0;float:inherit;padding:0;border:0px;border-radius:0px;-webkit-box-shadow: inherit;box-shadow: inherit;'>";
"<li class='divider'></li>";}
"<li class='dropdown-header'>" + value.ItemHeader + "</li>";}
"<li><a href='#' ItemData='" + Item.ItemData + "' >" + Item.ItemText + "</a></li>";
"</ul></li></ul></div></div>";
"input");
"") {SetData(SelText,SelData);}
"a").bind("click", function(e) {
"ItemData"));
"cut copy paste keydown", function(e) {e.preventDefault();}); 
"ul[style]");
"text-align: center"> JQuery组件基于Bootstrap的DropDownList(完整版)

这样通过两层的ul实现了下拉菜单,并且滚动条也没有覆盖右侧的两个圆角。较之上个版本,比较完善。

如果大家还想深入学习,可以点击这里进行学习,再为大家附3个精彩的专题:

Bootstrap学习教程

Bootstrap实战教程

Bootstrap插件使用教程

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。