<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Dialog - Default functionality</title>
<link rel="stylesheet" href="../jquery-ui-1.10.2.custom/development-bundle/themes/base/jquery.ui.all.css">
<script type="text/javascript" src="../jquery-ui-1.10.2.custom/js/jquery-1.9.0.js"></script>
<script type="text/javascript" src="../jquery-ui-1.10.2.custom/js/jquery-ui-1.10.2.custom.js"></script>
<script type="text/javascript" src="../jquery-ui-1.10.2.custom/development-bundle/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="../jquery-ui-1.10.2.custom/development-bundle/ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../jquery-ui-1.10.2.custom/development-bundle/ui/jquery.ui.dialog.js"></script>    <script> $(function() {
        $("#dialog").hide();//怎么让下面按钮绑定的方法(该按钮还绑定了其他方法)转移到对话框的ok按钮上?前提是不复制代码到ok按钮的function中,
        $(".btn").bind("click", function(){
            alert("123");
        });        $(".btn").click(function(){
            $( "#dialog" ).dialog({
                buttons: {
                    "ok": function(){                    }
                }
            });        });
    });
</script>
</head>
<body>
    <button type="button" class="btn"> click</button>
    <div id="dialog" title="Basic dialog">
        <p>对话框.</p>
    </div>
</body>
</html>dialog 按钮事件dialog按钮HTMLjquery

解决方案 »

  1.   

    不知道是不是这个意思
    function fn(){
                alert("123");
            }

      $(".btn").bind("click", fn);        $(".btn").click(function(){
                $( "#dialog" ).dialog({
                    buttons: {
                        "ok": fn
                    }
                });        });
      

  2.   

    就是点击click这个按钮, 不再弹出123这个alert框 , 而是弹出dialog,点击dialog的ok按钮会弹出123这个alert框,
      

  3.   

    你的 $(".btn")同时绑有, alert("123")和打开.dialog窗对吧,你可不可以把它分开写,
    如,
    fn123 function(){
    alert(123);
    }-----
    然后在dialog 中再用fn123
      

  4.   

    类似于alert("123")这类绑定到按钮上的方法是前人写好的,楼主需要做的是指在按钮和这类方法之间加一个对话框,点击按钮,弹出对话框,点击ok来确定调用alert("123")这类方法今天请教了个大神,给出的答复是将原本按钮上用来绑定alert("123")这类方法的class或id去掉,然后在ok按钮上添加相同的id或class或name, 个人觉得方法不错,尝试中