jquery 对话框标题动态

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20741524/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 01:17:31  来源:igfitidea点击:

jquery dialog title dynamically

jquery

提问by mahesh

how to change jquery dialog title dynamically here is the code we are using this will show normal title but we have to update depending on the code.

如何动态更改 jquery 对话框标题这里是我们正在使用的代码,这将显示正常标题,但我们必须根据代码进行更新。

<!doctype html>
<html lang="en">
 <head>
   <meta charset="utf-8">
<title>jQuery UI Dialog - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

<script>
$(function() {
  $( "#dialog" ).dialog();
 });
  </script>
 </head>
<body>

 <div id="dialog" title="Basic dialog">
     <p>This is the default dialog which is useful for displaying information.</p>
   </div>


   </body>
   </html>

回答by Tomanow

$('#dialog').attr('title', 'New Title').dialog();

OR

或者

$( "#dialog" ).dialog({ title: "New Dialog Title" });

回答by Arun P Johny

use the title option

使用标题选项

$(function () {
    $("#dialog").dialog({
        title: 'new'
    });
});

Demo: Fiddleor Fiddle2

演示:FiddleFiddle2

回答by Kevbo

Neither of these worked for me. However, this did...

这些都不适合我。然而,这确实...

$("#dlg").dialog("option","title","New Title").dialog('open');

回答by MJVM

I agree with the existing answers just if you would like to add additional properties like height, weight and how the model should behave and where to call another function see below code:

我同意现有的答案,如果您想添加其他属性,如高度、重量以​​及模型的行为方式以及调用另一个函数的位置,请参见以下代码:

     $( "#dialog-confirm" ).dialog({
    resizable: false,
    height: "auto",
    width: 400,
    modal: true,
    title: "Delete Personnel Record",
      buttons: {

        "Delete": function() {
         //-----------Calling function once Delete button is clicked----//
            RemovePersonal(PID);

          $( this ).dialog( "close" );

        },

        Cancel: function() {

          $( this ).dialog( "close" );

        }

      }

});

function RemovePersonal(id)
{
    //--------Call your function to remove record------//
    //-----------Or any other logic you want to implement---//
}