Dar*_*kes 1 jquery-ui jquery-plugins jquery-ui-dialog
javascript中的jquery-ui对话框窗口:
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Ok": function() {
$( this ).dialog( "close" );
},
"Cancel": function() {
$( this ).dialog( "close" );
}
}
});
Run Code Online (Sandbox Code Playgroud)
有两个按钮"Ok"和"Cancel".每个按钮都有功能.按钮名称几乎没有固定.有一些方法可以从变量中命名按钮吗?像这样:
var Button1 = "Ok";
var Button2 = "Cancel";
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
Button1: function() {
$( this ).dialog( "close" );
},
Button2: function() {
$( this ).dialog( "close" );
}
}
});
Run Code Online (Sandbox Code Playgroud)
我尝试上面的代码,但按钮出现名称"Button1"和"Button2".我还可以在按钮中显示图像但不能显示文本吗?
Dhr*_*gar 11
参考http://jqueryui.com/demos/dialog/,你可以看到有两种定义按钮的方法,一种是你在这里使用的,第二种是使用数组.
var button1 = 'Ok';
var button2 = 'Not Ok';
$( ".selector" ).dialog({ buttons: [
{
text: button1,
click: function() { $(this).dialog("close"); }
},
{
text: button2,
click: function() { $(this).dialog('close'); }
}
] });
Run Code Online (Sandbox Code Playgroud)
看起来这必须解决您的问题.
| 归档时间: |
|
| 查看次数: |
6210 次 |
| 最近记录: |