为什么第二个jQuery对话框的标题在弹出时不会改变。第一个对话框--我使用以下.attr("title", "Confirm")
更改该框的标题--它将第一个对话框的标题更改为‘确认’,就像它应该有的那样。现在,当第二个框弹出时,它应该将标题更改为'Message‘,因为对第二个框做了同样的事情-- .attr("title", "Message")
。对吗?但事实并非如此。它让标题从以前开始保持不变。然而,消息的变化是应该发生的。我已经测试了IE8,Chrome和FF3.6。
<div id="dialog-confirm" title=""></div>
<--这是jQuery函数之前的html。
Javascript / jQuery
$('#userDelete').click(function() {
$(function() {
var dialogIcon = "<span class=\"ui-icon ui-icon-alert\"></span>";
var dialogMessage = dialogIcon + "Are you sure you want to delete?";
$("#dialog-confirm").attr("title", "Confirm").html(dialogMessage).dialog({
resizable: false,
height: 125,
width: 300,
modal: true,
buttons: {
'Delete': function() {
$(this).dialog('close');
$.post('user_ajax.php', {action: 'delete',
aId: $('[name=aId]').val()
}, function(data) {
if(data.success){
var dialogIcon = "<span class=\"ui-icon ui-icon-info\"></span>";
var dialogMessage = dialogIcon + data.message;
$('#dialog-confirm').attr("title", "Message");
$('#dialog-confirm').html(dialogMessage);
$('#dialog-confirm').dialog({
resizable: false,
height: 125,
width: 300,
modal: true,
buttons: {
'Okay': function() {
$(this).dialog('close');
var url = $_httpaddress + "admin/index.php"
$(location).attr('href',url);
} // End of Okay Button Function
} //--- End of Dialog Button Script
});//--- End of Dialog Function
} else {
$_messageConsole.slideDown();
$_messageConsole.html(data.message);
}
}, 'json');
}, //--- End of Delete Button Function
'Cancel': function() {
$(this).dialog('close');
} //--- End of Cancel Button Function
} //--- End of Dialog Button Script
}); //--- End of Dialog Script
}); //--- End of Dialog Function
return false;
});
如果你愿意帮忙的话,谢谢你的助手。
发布于 2010-03-14 14:26:39
不用经过你所有的代码。我想$('#dialog-confirm').attr("title", "Message");
第二次不能工作了,因为jQuery UI对话框已经对实际的DOM进行了更改。因此,更改div的title
属性不会做任何事情。因为实际的标题可能是一些div
/p
或jQuery UI对话框生成的类似内容。
您对$('#dialog-confirm').dialog({..})
的第二次调用只需使用新选项更新现有的对话框。
检查jQuery UI对话框文档时,您应该注意到您可以简单地传递一个标题选项。所以第二次
$('#dialog-confirm').attr("title", "Message");
$('#dialog-confirm').html(dialogMessage);
$('#dialog-confirm').dialog({
resizable: false,
height: 125,
width: 300,
...
});
只管用
$('#dialog-confirm').html(dialogMessage);
$('#dialog-confirm').dialog({
resizable: false,
height: 125,
width: 300,
...
"title", "Message" //NEW!
});
发布于 2012-09-25 12:34:21
jQuery UI对话框还提供了一个方法“选项”,允许您在不重新配置整个对话框的情况下更改对话框上的选项。因此,如果您只想用新的标题再次显示相同的对话框,可以使用以下内容:
$('#dialog-confirm').dialog("option", "title", "Message");
$('#dialog-confirm').dialog("open");
发布于 2012-01-31 03:28:48
这对我有效(我用firebug来获得元素名)..
document.getElementById("ui-dialog-title-"+formname).innerHTML = "New title";
https://stackoverflow.com/questions/2443956
复制