jquery 弹出层实现代码
作者:bea
经过分析,网上的参考,终于搞定了~~ jQuery插件代码: 代码如下: jQuery.fn.selectItem = function(targetId) { var _seft = this; var targetId = $(targetId); this.toggle( function() { var A_top = $(this).offset().top + $(this).outerHeight(true); // 1 var A_left
经过分析,网上的参考,终于搞定了~~
jQuery插件代码:
代码如下:
jQuery.fn.selectItem = function(targetId) {
var _seft = this;
var targetId = $(targetId);
this.toggle(
function() {
var A_top = $(this).offset().top + $(this).outerHeight(true); // 1
var A_left = $(this).offset().left;
targetId.bgiframe();
targetId.show().css({ "position": "absolute", "top": A_top + "px", "left": A_left + "px" });
}
, function() {
targetId.hide();
}
);
targetId.find("#selectItemClose").click(function() {
targetId.hide();
});
targetId.find("#selectSub :checkbox").click(function() {
targetId.find(":checkbox").attr("checked", false);
$(this).attr("checked", true);
_seft.val($(this).val());
targetId.hide();
});
$(document).click(function(event) {
if (event.target.id != _seft.selector.substring(1)) {
targetId.hide();
}
});
targetId.click(function(e) {
e.stopPropagation();
});
return this;
}
HTML代码:
代码如下:
<input type="text" id="txtCompetencies" value="All" readonly="readonly"/>
<div id="selectCompetencies">
<table>
<tbody>
<tr><td><input type="checkbox" />All</td></tr>
<tr><td><input type="checkbox" />Confidence</td></tr>
</tbody>
</table>
</div>
css样式:
代码如下:
/* pop div begin */
.selectItemcont{padding:8px;}
.selectItemtit{line-height:20px;height:20px;margin:1px;padding-left:12px;}
.bgc_ccc{background:#E88E22;}
.selectItemleft{float:left;margin:0px;padding:0px;font-size:12px;font-weight:bold;color:#fff;}
.selectItemright{float:right;cursor:pointer;color:#fff;}
.selectItemcls{clear:both;font-size:0px;height:0px;overflow:hidden;}
.selectItemhidden{display:none;}
#selectCompetencies
{
display:none;
background:#FFF;
position:absolute;
top:0px;
left:center;
border:1px solid #000;
overflow-x:hidden;
overflow-y:auto;
width:250px;
z-index:1000;
max-height:200px;
}
/* pop div end */
JavaScript代码:
代码如下:
$("#txtCompetencies").selectItem("#selectCompetencies");
实现点击文本框,在其正下方弹出一个新的层,再次点击的时候,隐藏层。
后面的话,我会把这个插件继续完善的~~~ O(∩_∩)O...
有用 | 无用
jQuery插件代码:
代码如下:
jQuery.fn.selectItem = function(targetId) {
var _seft = this;
var targetId = $(targetId);
this.toggle(
function() {
var A_top = $(this).offset().top + $(this).outerHeight(true); // 1
var A_left = $(this).offset().left;
targetId.bgiframe();
targetId.show().css({ "position": "absolute", "top": A_top + "px", "left": A_left + "px" });
}
, function() {
targetId.hide();
}
);
targetId.find("#selectItemClose").click(function() {
targetId.hide();
});
targetId.find("#selectSub :checkbox").click(function() {
targetId.find(":checkbox").attr("checked", false);
$(this).attr("checked", true);
_seft.val($(this).val());
targetId.hide();
});
$(document).click(function(event) {
if (event.target.id != _seft.selector.substring(1)) {
targetId.hide();
}
});
targetId.click(function(e) {
e.stopPropagation();
});
return this;
}
HTML代码:
代码如下:
<input type="text" id="txtCompetencies" value="All" readonly="readonly"/>
<div id="selectCompetencies">
<table>
<tbody>
<tr><td><input type="checkbox" />All</td></tr>
<tr><td><input type="checkbox" />Confidence</td></tr>
</tbody>
</table>
</div>
css样式:
代码如下:
/* pop div begin */
.selectItemcont{padding:8px;}
.selectItemtit{line-height:20px;height:20px;margin:1px;padding-left:12px;}
.bgc_ccc{background:#E88E22;}
.selectItemleft{float:left;margin:0px;padding:0px;font-size:12px;font-weight:bold;color:#fff;}
.selectItemright{float:right;cursor:pointer;color:#fff;}
.selectItemcls{clear:both;font-size:0px;height:0px;overflow:hidden;}
.selectItemhidden{display:none;}
#selectCompetencies
{
display:none;
background:#FFF;
position:absolute;
top:0px;
left:center;
border:1px solid #000;
overflow-x:hidden;
overflow-y:auto;
width:250px;
z-index:1000;
max-height:200px;
}
/* pop div end */
JavaScript代码:
代码如下:
$("#txtCompetencies").selectItem("#selectCompetencies");
实现点击文本框,在其正下方弹出一个新的层,再次点击的时候,隐藏层。
后面的话,我会把这个插件继续完善的~~~ O(∩_∩)O...
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- JS OOP包机制,类创建的方法定义
- JQuery 网站换肤功能实现代码
- Javascript结合css实现网页换肤功能
- 简单实用的HTML到UBB转换脚本工具实现说明
- cnblogs csdn 代码运行框实现代码
- 键盘 keycode的值 javascript时触发事件时很有用的要素
- js 函数的执行环境和作用域链的深入解析
- 提高网站性能之 如何对待JavaScript
- JavaScript Sort 表格排序
- DOM 脚本编程中的兄弟节点
- javascript GUID生成器实现代码
- JavaScript中的JSON 中文版翻译
- json 实例详细说明教程
- json 入门基础教程 推荐
- jquery text()要注意啦
- CCPry JS类库 代码
- Iframe 自适应高度并实时监控高度变化的js代码
- 扩展jQuery 键盘事件的几个基本方法
- jQuery 扩展对input的一些操作方法