//自定义confirm插件
//自定义confirm插件
//思路:1.事件操作:显示id为myConfirm的div层,并返回false;
// 2.事件操作:回调函数调用trigger()方法去自动执行事件,改变status的状态值,返回status;
var status=false;//定义为全局对象:记录dialog执行状态
$.fn.MyConfirm = function ($clickObj,$dialogObj) {
$dialogObj.dialog(
{ title: ‘确认框‘,
position: [100, 100],
modal:true,
buttons: {
‘ok‘: function () {
// $dialogObj.dialog(‘close‘);
status=true;
callback($clickObj,true,$dialogObj);
},
‘cancle‘: function () {
// $dialogObj.dialog(‘close‘);
status=false;
callback($clickObj,false,$dialogObj);
}
},
}
);
$dialogObj.text(" 确定要删除吗?");
return status;
}
function callback($clickObj,status,$dialogObj){
if($clickObj)
{
if(status==true){
$clickObj.trigger(‘click‘);
}
$dialogObj.dialog(‘close‘);
}
}
//测试
<script type="text/javascript">
//测试
$(function () {
$("#Btn").click(function () {
return $.fn.MyConfirm($(‘#Btn‘), $("#myConfirm"));
});
});
</script>
html页面:
<form id="form1" runat="server">
<div id=‘myConfirm‘>
</div>
name:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Btn" runat="server" Text="submit" ClientIDMode="Static" OnClick="Btn_Click">
</asp:Button>
</form>