读书人

急 给按钮绑定一个对话框将按钮上的

发布时间: 2013-07-08 14:13:00 作者: rapoo

急急急!求助: 给按钮绑定一个对话框,将按钮上的原来事件转移到对话框的ok按钮上
<!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 按钮 HTML jquery
[解决办法]
不知道是不是这个意思
function fn(){
alert("123");
}
$(".btn").bind("click", fn);

$(".btn").click(function(){
$( "#dialog" ).dialog({


buttons: {
"ok": fn
}
});

});
[解决办法]
你的 $(".btn")同时绑有, alert("123")和打开.dialog窗对吧,

你可不可以把它分开写,
如,
fn123 function(){
alert(123);
}

-----
然后在dialog 中再用fn123

读书人网 >JavaScript

热点推荐