一個簡單的jquery的多選下拉框(自寫)
js代碼
(function(){
$.fn.extend({
checks_select: function(options){
jq_checks_select = null;
$(this).click(function(e){
jq_check = $(this);
//jq_check.attr("class", "");
if (jq_checks_select == null) {
jq_checks_select = $("<div class='checks_div_select'></div>").insertAfter(jq_check);
$.each(options, function(i, n){
check_div=$("<div><input type='checkbox' value='" + n + "'>" + n + "</div>").appendTo(jq_checks_select);
check_box=check_div.children();
check_box.click(function(e){
//jq_check.attr("value",$(this).attr("value") );
temp="";
$("input:checked").each(function(i){
if(i==0){
temp=$(this).attr("value");
}else{
temp+="、"+$(this).attr("value");
}
});
jq_check.attr("value",temp);
e.stopPropagation();
});
});
}else{
jq_checks_select.toggle();
}
e.stopPropagation();
});
$(document).click(function () {
jq_checks_select.hide();
});
//$(this).blur(function(){
//jq_checks_select.css("visibility","hidden");
//alert();
//});
}
})
})(jQuery);
html
<html>
<head>
<script type="text/javascript" src="js/jquery-1.3.2.js">
</script>
<script type="text/javascript" src="js/jquery2.1.js">
</script>
<script type="text/javascript" src="js/jquery-mah-UI.js">
</script>
<script language="javascript">
$(document).ready(function(){
var options = {
1: "第一個選擇項(xiàng)",
2: "第二個選擇項(xiàng)",
3: "第三個選擇項(xiàng)",
4: "第四個選擇項(xiàng)",
5: "第五個選擇項(xiàng)",
6: "第六個選擇項(xiàng)"
};
$("#test_div").checks_select(options);
});
</script>
<style>
.checks_div_select {
width: 150px;
background-color: #e9fbfb;
border: 1px solid #18cbcd;
font-family: 'Verdana', '宋體';
font-size: 12px;
position:absolute;
left:2px;
top:25px;
}
</style>
</head>
<body>
<div style="position:relative;">
<input type="text" id="test_div"/>
</div>
</body>
</html>
需要jquery類庫
相關(guān)文章
基于jQuery實(shí)現(xiàn)左右div自適應(yīng)高度完全相同的代碼
最近做前端設(shè)計(jì)時需要使左右兩個DIV高度自適應(yīng)。這其中的jquery代碼中的獲得高度用的clientHeight,介紹一下幾種不同的獲得方式以及他們的差別2012-08-08jQuery實(shí)現(xiàn)form表單基于ajax無刷新提交方法詳解
這篇文章主要介紹了jQuery實(shí)現(xiàn)form表單基于ajax無刷新提交方法,結(jié)合實(shí)例形式分析了jQuery使用$.ajax()方法實(shí)現(xiàn)無刷新提交的詳細(xì)步驟與實(shí)現(xiàn)技巧,并附帶了一個較為完整的實(shí)例供大家參考,需要的朋友可以參考下2015-12-12jQuery扁平化風(fēng)格下拉框美化插件FancySelect使用指南
這篇文章主要介紹了jQuery扁平化風(fēng)格下拉框美化插件FancySelect使用指南,需要的朋友可以參考下2015-02-02jQuery中attr()與prop()函數(shù)用法實(shí)例詳解(附用法區(qū)別)
這篇文章主要介紹了jQuery中attr()與prop()函數(shù)用法,結(jié)合實(shí)例形式詳細(xì)分析了attr()與prop()函數(shù)的使用技巧與相關(guān)注意事項(xiàng),并附帶了attr()與prop()函數(shù)用法的區(qū)別,需要的朋友可以參考下2015-12-12DataTables+BootStrap組合使用Ajax來獲取數(shù)據(jù)并且動態(tài)加載dom的方法(排序,過濾,分頁等)
Datatables是一款jquery表格插件。它是一個高度靈活的工具,可以將任何HTML表格添加高級的交互功能。這篇文章主要介紹了DataTables+BootStrap組合使用Ajax來獲取數(shù)據(jù)并且動態(tài)加載dom的方法(排序,過濾,分頁等),需要的朋友可以參考下2016-11-11EasyUI的treegrid組件動態(tài)加載數(shù)據(jù)問題的解決辦法
最近涉及到treegrid組件的查詢,需要根據(jù)查詢條件動態(tài)更新EasyUI的treegrid組件的動態(tài)加載查詢結(jié)果2011-12-12當(dāng)jQuery遭遇CoffeeScript的時候 使用分享
雖然對ruby不太了解,但是看到CoffeeScript詩一般的代碼確實(shí)被怔住了,和jQuery之前給我的感覺是如此的相似——都是一個字,美,當(dāng)jQuery遭遇到CoffeeScript時,會蹦出什么樣的火花呢?2011-09-09