|
//插件下載地址:http://abeautifulsite.NET/notebook/87
自身的原方法為:
復(fù)制代碼 代碼如下:
// Usage:
// jAlert( message, [title, callback] )
// jConfirm( message, [title, callback] )
// jPrompt( message, [value, title, callback] )
1.新加一個multicheckbox 的公共方法:
// Public methods
multicheckbox : function (message, value, title, callback) {
if (title == null ) title = 'multicheckbox ';
$.alerts._show(title, message, value, 'multicheckbox ', function (result) {
if (callback) callback(result);
});
},
2 .在私有方法_show:function (title, msg, value, type, callback){...} 中增加對multicheckbox 的控制:
// Private methods
------------------------ 關(guān)鍵部分 ------------------------------
case 'multicheckbox' :
$("#popup_message" ).append(value).after('<div id="popup_panel"> <span id="checkall" style="cursor:pointer;border:1px solid #FFCC35;font-family:宋體;font-weight:bold;background-color:#FFFF99;color:#0000CC;margin:3px;padding:3px 10px 3px 10px;">全選</span> <span id="popup_ok" style="cursor:pointer;border:1px solid #CF4342;font-family:宋體;font-weight:bold;background-color:#DFF1FF;color:#CF4342;margin:3px;padding:3px 10px 3px 10px;">確定</span> <span id="popup_cancel" style="cursor:pointer;border:1px solid #CF4342;font-family:宋體;font-weight:bold;background-color:#DFF1FF;color:#0000CC;margin:3px;padding:3px 10px 3px 10px;">取消</span></div> ');
var $spanHover = $("#dialog span" );
$spanHover.hover(
function () {$(this ).addClass("spanmousehover" );},
function () {$(this ).removeClass("spanmousehover" );}
);
$("#checkall" ).click(function () {
if ($("#checkall" ).html() == "全選" ) {
$("#dialog input" ).each(function () {$(this ).attr("checked" , true );});
$("#checkall" ).html("取消全選" );
}
else {
$("#dialog input" ).each(function () {$(this ).attr("checked" , false);});
$("#checkall" ).html("全選" );
}
});
$("#delcheckall" ).click(function () {
$("#dialog input" ).each(function () {$(this ).attr("checked" , false );});
});
$("#popup_ok" ).click(function () {
var getAll = "";
var test = $('#dialog input' ).each(function () {if (this .checked) {getAll += $(this ).val() + ',';}});
var valback = getAll.substring(0, getAll.length - 1);//去掉最后一個','號
$.alerts._hide();
$("#ctl00_ContentPlaceHolder_main_TextBox_recever_sel" ).blur();
if (callback) callback(valback);// 在單擊確定后將所有選中的內(nèi)容回傳到輸入框中
});
$("#popup_cancel" ).click(function() {
$.alerts._hide();
$("#ctl00_ContentPlaceHolder_main_TextBox_recever_sel" ).blur();
if (callback) callback(null);
});
/ /----------------------------------------------------------------------
在 // Shortuct functions 中增加如下名稱:
jMulticheckbox = function (message, value, title, callback) {
$.alerts.multicheckbox(message, value, title, callback);
};
3 .在前段代碼的input 輸入框(或ASP:TextBox )的onfocus 屬性中調(diào)用如下腳本:
jMulticheckbox('' , '<% = allcheckinfo.ToString() %> ' , '請選擇接收部門' , function (r) {
//定義傳入html元素,彈出框主標題,callback結(jié)果(即選擇的內(nèi)容)
if (r!=null )
$('#ctl00_ContentPlaceHolder_main_TextBox_recever_sel' ).val(r);
});
其 中"allcheckinfo.ToString() "可以為后臺從相應(yīng)的業(yè)務(wù)邏輯中取出的結(jié)果,如:
StringBuilder allinfo = new StringBuilder ("" );
allinfo.Append("<div id=/"dialog/" style=/"padding:0; margin:0;height:250px;width:280px;text-align:left;line-height:20px;overflow:auto/"> " );
...
while (OracleDataReader.Read())
{
string bumeninfo = oradr[0 ].ToString();
allinfo.Append("<span class=/"spanmouse/"><input name=/"chk1/" type=/"checkbox/" id=/"c" + flag + "/" value=/"" + bumeninfo + "/" /><label for=/"c" + flag + "/">" + bumeninfo + "</label></span><br />" );
}
...
allinfo.Append("</div>" );
即 將<div>...</div> 返回給JS,最后效果如下:

JavaScript技術(shù):jquery.alert 彈出式復(fù)選框?qū)崿F(xiàn)代碼,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。