在对话框上动态设置标题

时间:2010-01-21 09:37:21

标签: jquery-ui

    var dlg = $("#dialog").dialog({
      autoOpen: false,
      modal: true,
      buttons: {
        'Update': function() {
          alert(clientCode);
        },
        Cancel: function() {
          $(this).dialog('close');
        }
      }
    });

    $(".edit").click(function() {
      myval = $(this).parent().children('td:nth-child(1)').text();
      dlg.dialog('open');
      return false;
    });

如何获取“myval”并将其作为对话框的标题?我在尝试dlg.dialog('open', myval)并且没有运气时尝试将其作为参数传递。我也尝试将它作为参数传递,但也没有运气。然而,我可能以错误的方式做事。

2 个答案:

答案 0 :(得分:8)

$("#your-dialog-id").dialog({
    open: function() {
        $(this).dialog("option", "title", "My new title");
    }
});

答案 1 :(得分:4)

在click-event中创建对话框并使用它来设置标题:

类似的东西:

$(".edit").click(function() {
  myval = $(this).parent().children('td:nth-child(1)').text();

  var dlg = $("#dialog").dialog({
  autoOpen: false,
  title: myval,
  modal: true,
  buttons: {
      'Update': function() {
        alert(clientCode);
      },
      Cancel: function() {
        $(this).dialog('close');
      }
    }
  });

  dlg.dialog('open');
  return false;
});
相关问题