js,jq实现对话框,自己写的 本帖最后由 edfdfg 于 2014-10-14 15:07:22 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var AppDaliog = { confirm: function(msg, title,ok,cancle) {//ok 确定函数 cancle取消函数 if ($().length == 0) { var html = new Array(); html.push("<div id='appAlert' class='dlgMain'><div class='dlgContext'><div class='dlgHead'>" + title + "</div>"); html.push("<div class='dlgShow'>" + msg + "</div><div class='dlgFoot'><a href='javascript::' class='button' id='ok_qxy_confirm'>确定</a>") html.push("<a href='#' class='button' id='cancle_qxy_confirm'>取消</a> </div></div>"); // html.push("<script type='text/javascript'> $('#ok_qxy_confirm').click(function() {if (ok != undefined) {$('#appAlert').hide();ok();}else{ $('#appAlert').hide(); }});"); // html.push(" $('#cancle_qxy_confirm').click(function() {if (cancle != undefined) {$('#appAlert').hide();cancle();}else{ $('#appAlert').hide();} });</script>");var dddd=$(html.join(""));dddd.find('#ok_qxy_confirm').click(ok);dddd.find('#cancle_qxy_confirm').click(cancle); $('body').append(dddd); $("#appAlert").show(); } else { $("#appAlert").show(); } }, alert: function() { } } <div id='appAlert' class='confirm' name='confirm'> <div class='title' name='title'></div> <div class='body' name='body'></div> <div class='bottom' > <button name='btok'>OK</button> <button name='btcancel'>Cancel</button> </div></div>var AppDaliog = { confirm: function(msg, title,ok,cancle) {//ok 确定函数 cancle取消函数 $("#appAlert").find('[name=title]').html(title); $("#appAlert").find('[name=body]').html(msg); $("#appAlert").find('[name=btok]').unbind().click(function(){ok && ok();$("#appAlert").hide();});$("#appAlert").find('[name=btcancel]').unbind().click(function(){cancle && cancle();$("#appAlert").hide();}); $("#appAlert").show(); }, alert: function() { } }这个不是最优化的写法 怎么样才是最优的?对了 不能把div 之类的 弄出来,因为我先做的 就是以后用这个类的时候 直接拉这个类过来调用就行了,要是你把那div写在外面....那岂不是每次调用都要在页面复制一遍?对了,不能把 原谅我脑子不太好使...这样的,貌似我用2楼的方法做,成功了但是我想做的是,不管执行ok 还是cancle()都要关闭窗口,才执行那个函数,我就改了一下变成这样....前面一样var dddd=$(html.join("")); dddd.find('#ok_qxy_confirm').click(funtion(){$('#appAlert' ).hide();//先隐藏if(ok!=undefined){ ok();}}); dddd.find('#cancle_qxy_confirm').click(funtion(){$('#appAlert' ).hide();//先隐藏 if(cancle!=undefined){cancle();}}); 为什么 不能执行了? jquey jajx返回值data是个数组,如何取值。 如何将以下代码改不兼容google chromium 关于Spry折叠式的设置 javascript 与 windows2003下的IE7安全问题 如何在静态网页或 asp网页中进行link修改 【初学】请问jquery 如何在 ready() 函数之外使用jquery的东西? 有关跨域自动点击的问题 js如何提交iframe中的表单 <map>中<area>里点击区域的坐标怎么确定? 哪位兄弟帮我把javascript的md5页面改成asp页面能调用执行 有无多笔连动下拉选单范例? extjs5用sencha cmd无法创建项目
confirm: function(msg, title,ok,cancle) {//ok 确定函数 cancle取消函数
if ($().length == 0) {
var html = new Array();
html.push("<div id='appAlert' class='dlgMain'><div class='dlgContext'><div class='dlgHead'>" + title + "</div>");
html.push("<div class='dlgShow'>" + msg + "</div><div class='dlgFoot'><a href='javascript::' class='button' id='ok_qxy_confirm'>确定</a>")
html.push("<a href='#' class='button' id='cancle_qxy_confirm'>取消</a> </div></div>");
// html.push("<script type='text/javascript'> $('#ok_qxy_confirm').click(function() {if (ok != undefined) {$('#appAlert').hide();ok();}else{ $('#appAlert').hide(); }});");
// html.push(" $('#cancle_qxy_confirm').click(function() {if (cancle != undefined) {$('#appAlert').hide();cancle();}else{ $('#appAlert').hide();} });</script>");
var dddd=$(html.join(""));
dddd.find('#ok_qxy_confirm').click(ok);
dddd.find('#cancle_qxy_confirm').click(cancle);
$('body').append(dddd);
$("#appAlert").show();
}
else {
$("#appAlert").show();
}
},
alert: function() { }
}
<div class='title' name='title'></div>
<div class='body' name='body'></div>
<div class='bottom' >
<button name='btok'>OK</button> <button name='btcancel'>Cancel</button>
</div>
</div>var AppDaliog = {
confirm: function(msg, title,ok,cancle) {//ok 确定函数 cancle取消函数
$("#appAlert").find('[name=title]').html(title);
$("#appAlert").find('[name=body]').html(msg);
$("#appAlert").find('[name=btok]').unbind().click(function(){ok && ok();$("#appAlert").hide();});
$("#appAlert").find('[name=btcancel]').unbind().click(function(){cancle && cancle();$("#appAlert").hide();});
$("#appAlert").show();
},
alert: function() { }
}
这个不是最优化的写法
对了 不能把div 之类的 弄出来,因为我先做的 就是以后用这个类的时候 直接拉这个类过来调用就行了,要是你把那div写在外面....那岂不是每次调用都要在页面复制一遍?对了,不能把
但是我想做的是,不管执行ok 还是cancle()都要关闭窗口,才执行那个函数,我就改了一下变成这样....前面一样
var dddd=$(html.join(""));
dddd.find('#ok_qxy_confirm').click(funtion(){
$('#appAlert' ).hide();//先隐藏
if(ok!=undefined){
ok();
}});
dddd.find('#cancle_qxy_confirm').click(funtion(){
$('#appAlert' ).hide();//先隐藏
if(cancle!=undefined){
cancle();
}}); 为什么 不能执行了?