jquery对话框标题动态

时间:2013-12-23 10:25:27

标签: jquery

如何动态更改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>

4 个答案:

答案 0 :(得分:16)

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

OR

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

答案 1 :(得分:11)

使用title option

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

演示:FiddleFiddle2

答案 2 :(得分:5)

这些都不适合我。但是,这确实......

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

答案 3 :(得分:0)

只要您想添加其他属性(例如身高,体重以及模型应如何运行以及在何处调用其他函数),我都同意现有的答案,

     $( "#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---//
}