我做了这个功能,改变了我的对话标题。但我不知道,这是否正确。当你这样做时我想要那样:
$("#dialog").dialog({ autoOpen: false, title: n });
然后标题 - “yyy”,更改为“xxxyyy”。但我无法弄明白,怎么做?
<div id="dialog" style="display: none;">hello</div>
<button id="opener">Open Dialog</button>
<button id="change"> Change name </button>
<script>
var n = 'Basic Title';
var x = '';
var $dialog = $("#dialog").dialog({ autoOpen: false, title: n });
$("#opener").click(function() { $dialog.dialog("open"); });
$("#change").click(function() {
var x = prompt("New title");
if (x === n){
var $dialog = $("#dialog").dialog({autoOpen: false, title: n});
} else {
var $dialog = $("#dialog").dialog({autoOpen: false, title: "xxx" + x});
}
$dialog.dialog("open");
});
</script>
所以,我在我的jQuery UI中添加了“xxx”+:
_title: function( title ) {
if ( !this.options.title ) {
title.html(" ");
}
title.text( "xxx" + this.options.title );
},
但是我想在那里添加它,而不需要编辑默认的jQuery UI。 我尝试在另一个脚本文件中执行此操作,我尝试使用它 $ .getScript(“js / jquery-ui-1.10.4.custom.js”,function(){ 所以我现在可以从其他地方修改jQuery代码,但我无法弄清楚如何编辑它。如果我只是复制粘贴该功能,它将不起作用:(
这是我需要的照片:)
$.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, {
_title: function (title) {
if (!this.options.title) {
title.html(" ");
}
title.html("xxx" + this.options.title);
}
}));
答案 0 :(得分:0)
你所拥有的非常接近,但你不需要为标题更改创建新的对话框。
$("#change").click(function () {
var x = prompt("New title");
var title = $("#dialog").dialog("option", "title"); // get existing title
if (x != n) {
$("#dialog").dialog("option", "title", title + "" + x); // set new title
}
});