对话框标题更改

时间:2014-12-12 15:23:16

标签: jquery html

我无法找到关于jQuery对话框标题的答案。设置对话框标题后,我需要在该字符串前面添加" abc"。在执行此$("#dialog")。对话框("选项","标题"," efg")对话框标题更改为& #34; ABCDEF&#34 ;.但是这一行$("#dialog"。)对话框("选项","标题"," def")不应该在所有。这对我来说不是正确答案:

var title = 'abc';
$("#dialog").dialog();
$("#dialog").dialog("option","title", title+"def"); 

我试过这个,但它对我不起作用: HTML:

<div id="dialog">I'm in a dialog</div>

的javascript:

  $(document).ready(function() {

    $("#dialog").dialog();
    $("#dialog").attr("title",function(){return "abc" + this.title});
    $("#dialog").dialog("option","title","def");

});

1 个答案:

答案 0 :(得分:1)

我不确定我完全明白你的意思&#34; def&#34;根本不应该改变....

也就是说,这是一个解决当前标题,存储它然后追加它的解决方案。

   $(document).ready(function() {
       $("#dialog").dialog();
       $("#dialog").dialog("option","title","def");
       var curTitle =  $("#dialog").dialog("option","title");
       //alert(curTitle);
       $("#dialog").dialog("option","title","abc" + curTitle); 
   });

http://jsfiddle.net/xbo6upxk/


更新:

好的,我认为这就是你想要做的事情:

<div id="dialog" title="Default Title">I'm in a dialog</div>

和js:

  $(document).ready(function() {
     var curTitle =  $("#dialog").attr("title");
     alert(curTitle);
     $("#dialog").dialog();
     alert('see my default title?  i will change now!');
     $("#dialog").dialog("option","title","def");
     curTitle =  $("#dialog").dialog("option","title");
     alert(curTitle);
     $("#dialog").dialog("option","title","abc" + curTitle);   
 });

http://jsfiddle.net/ekc9r3hj/2/


更新2:

$(document).ready(function() {
    $("#dialog").dialog();      
    $("#dialog").dialog("option","title","abc" + $("#dialog").dialog("option","title"));
});

http://jsfiddle.net/8y2jwwhs/1/