我有一个非常简单的对话框
<script>
$(function() {
$( "#openDialog").on("click", function(){
$( "#dialog-modal" ).dialog({
height: 300,
width: 600,
modal: true,
buttons: {
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
$( "#dialog-modal" ).show();
});
});
</script>
我使用HTML表填充此对话框,该表具有从Java方法传递给它的信息。我可以在页面加载时使用,但我希望用户加载信息打开对话框。
我检查了jquery ui的API,对话框有一个beforeClose函数但没有beforeOpen函数。这样做的最佳方式是什么?当用户打开对话框(在.show上)时,我尝试过回调,但是我无法正常工作
<script>
$(function() {
$( "#openDialog").on("click", function(){
$( "#dialog-modal" ).dialog({
height: 300,
width: 600,
modal: true,
buttons: {
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
$( "#dialog-modal" ).show(function(
JavaClass.javaMethod();
));
});
});
</script>
答案 0 :(得分:0)
为什么不
<script>
$(function() {
$( "#openDialog").on("click", function(){
if (shouldOpenDialog()){ // Do what you must do here
$( "#dialog-modal" ).dialog({
height: 300,
width: 600,
modal: true,
buttons: {
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
$( "#dialog-modal" ).show();
}
});
});
</script>
编辑:或者,如果您的验证是异步的,
<script>
$(function() {
$( "#openDialog").on("click", function(){
if (shouldOpenDialog(function() { // Do what you must do here
$( "#dialog-modal" ).dialog({
height: 300,
width: 600,
modal: true,
buttons: {
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
$( "#dialog-modal" ).show();
});
});
});
</script>
具有
function shouldOpenDialog(callback) {
asyncCall(onComplete: function(o){
if (o.ok)
callback();
});
}