本帖最后由 edfdfg 于 2014-10-14 15:07:22 编辑

解决方案 »

  1.   

    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() { }
     
    }
      

  2.   

    <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() { }
     
    }
    这个不是最优化的写法  
      

  3.   

    怎么样才是最优的?
    对了 不能把div 之类的 弄出来,因为我先做的 就是以后用这个类的时候 直接拉这个类过来调用就行了,要是你把那div写在外面....那岂不是每次调用都要在页面复制一遍?对了,不能把
      

  4.   

    原谅我脑子不太好使...这样的,貌似我用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();
    }});   为什么 不能执行了?