Javascript 加载回调后jQuery ui对话框更改标题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2171763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery ui dialog change title after load-callback
提问by Guido Lemmens 2
I like to change the title from an UI Dialog after i have submitted a form in this UI Dialog. So in the callback-function after loadi should suggest, but i've tried and googled without result.
我喜欢在此 UI 对话框中提交表单后更改 UI 对话框的标题。所以在load我应该建议之后的回调函数中,但我已经尝试并用谷歌搜索没有结果。
Has anyone an idea?
有人有想法吗?
回答by Nick Craver
Using dialog methods:
使用对话方法:
$('.selectorUsedToCreateTheDialog').dialog('option', 'title', 'My New title');
Or directly, hacky though:
或者直接,hacky:
$("span.ui-dialog-title").text('My New Title');
For future reference, you can skip google with jQuery. The jQuery API will answer your questions most of the time. In this case, the Dialog API page. For the main library: http://api.jquery.com
为了将来参考,您可以使用 jQuery 跳过 google。大多数情况下,jQuery API 将回答您的问题。在这种情况下,对话框 API 页面. 对于主库:http: //api.jquery.com
回答by workdreamer
I have found simpler solution:
我找到了更简单的解决方案:
$('#clickToCreate').live('click', function() {
$('#yourDialogId')
.dialog({
title: "Set the title to Create"
})
.dialog('open');
});
$('#clickToEdit').live('click', function() {
$('#yourDialogId')
.dialog({
title: "Set the title To Edit"
})
.dialog('open');
});
Hope that helps!
希望有帮助!
回答by storvas
An enhancement of the hacky idea by Nick Craver to put custom HTML in a jquery dialog title:
Nick Craver 改进了将自定义 HTML 放在 jquery 对话框标题中的 hacky 想法:
var newtitle= '<b>HTML TITLE</b>';
$(".selectorUsedToCreateTheDialog").parent().find("span.ui-dialog-title").html(newtitle);
回答by Tim B.
I tried to implement the result of Nick which is:
我试图实现尼克的结果,即:
$('.selectorUsedToCreateTheDialog').dialog('option', 'title', 'My New title');
But that didn't work for me because i had multiple dialogs on 1 page. In such a situation it will only set the title correct the first time. Trying to staple commands did not work:
但这对我不起作用,因为我在 1 页上有多个对话框。在这种情况下,它只会在第一次正确设置标题。尝试装订命令不起作用:
$("#modal_popup").html(data);
$("#modal_popup").dialog('option', 'title', 'My New Title');
$("#modal_popup").dialog({ width: 950, height: 550);
I fixed this by adding the title to the javascript function arguments of each dialog on the page:
我通过将标题添加到页面上每个对话框的 javascript 函数参数来解决这个问题:
function show_popup1() {
$("#modal_popup").html(data);
$("#modal_popup").dialog({ width: 950, height: 550, title: 'Popup Title of my First Dialog'});
}
function show_popup2() {
$("#modal_popup").html(data);
$("#modal_popup").dialog({ width: 950, height: 550, title: 'Popup Title of my Other Dialog'});
}
回答by user4629979
Even better!
甚至更好!
jQuery( "#dialog" ).attr('title', 'Error');
jQuery( "#dialog" ).text('You forgot to enter your first name');

