使用另一个对话框的功能更改jQuery-UI对话框的标题 [英] Changing the title of jQuery-UI dialog-box with in another dialog-box's function

查看:91
本文介绍了使用另一个对话框的功能更改jQuery-UI对话框的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么弹出第二个jQuery-UI对话框标题时没有更改.我使用以下.attr("title", "Confirm")更改第一个对话框的标题-就像应该的那样,它将第一个对话框的标题更改为'Confirm'.现在,当第二个框弹出时,应该将标题更改为"Message",因为对第二个框做了相同的操作-.attr("title", "Message").正确的?但事实并非如此.它保留了以前的标题.但是,消息更改应有的状态.我已经在IE8,Chrome和FF3.6中进行了测试.

Why doesn't doesn't the second jQuery-UI dialog box title change when popped. The first dialog box I change the title of the box with using the following .attr("title", "Confirm") -- it change the title of the first box to 'Confirm', like it should have. Now when the second box pops up it should change the title to 'Message' since did the same thing for the second box -- .attr("title", "Message"). Right? But it doesnt. It keep the title from before. However, the message change like it should have. I have tested in IE8, Chrome, and FF3.6.

<div id="dialog-confirm" title=""></div><-这是jQuery函数之前的html.

<div id="dialog-confirm" title=""></div> <-- This is the html before jQuery functions.

$('#userDelete').click(function() {
$(function() {
var dialogIcon = "<span class=\"ui-icon ui-icon-alert\"></span>";
var dialogMessage = dialogIcon + "Are you sure you want to delete?";
$("#dialog-confirm").attr("title", "Confirm").html(dialogMessage).dialog({
    resizable: false,
    height:    125,
    width:     300,
    modal:     true,
    buttons:  {
    'Delete': function() {
        $(this).dialog('close');
        $.post('user_ajax.php', {action: 'delete',
                 aId: $('[name=aId]').val()
        }, function(data) {
            if(data.success){
                var dialogIcon = "<span class=\"ui-icon ui-icon-info\"></span>";
                var dialogMessage = dialogIcon + data.message;
                $('#dialog-confirm').attr("title", "Message");
                $('#dialog-confirm').html(dialogMessage);
                $('#dialog-confirm').dialog({
                    resizable: false,
                    height:    125,
                    width:     300,
                    modal:     true,
                    buttons:  {
                    'Okay': function() {
                        $(this).dialog('close');
                        var url = $_httpaddress + "admin/index.php"
                        $(location).attr('href',url);
                    } // End of Okay Button Function
                    } //--- End of Dialog Button Script
                });//--- End of Dialog Function
            } else {
                $_messageConsole.slideDown();
                $_messageConsole.html(data.message);
            }
        }, 'json');
    }, //--- End of Delete Button Function
    'Cancel': function() {
        $(this).dialog('close');
    } //--- End of Cancel Button Function 
    } //--- End of Dialog Button Script
}); //--- End of Dialog Script
}); //--- End of Dialog Function
return false; 
});

如果您选择帮助,谢谢您的助手.

推荐答案

无需遍历所有代码.我猜$('#dialog-confirm').attr("title", "Message");第二次不起作用,因为jQuery UI对话框已经对实际DOM进行了更改.因此,更改div的title属性不会执行任何操作.由于实际标题可能是jQuery UI对话框生成的某些div/p或类似名称.

Without going through all your code. I guess $('#dialog-confirm').attr("title", "Message"); doesn't work the second time because jQuery UI Dialog already made changes to the actual DOM. So changing the title attribute of the div doesn't do anything. As the actual title is probably some div/p or similar generated by jQuery UI Dialog.

您第二次打电话给您$('#dialog-confirm').dialog({..})只需使用新选项更新现有对话框即可.

Your second call to you $('#dialog-confirm').dialog({..}) simply updates an existing dialog with new options.

在检查jQuery UI对话框文档时,您应该已经注意到,您可以简单地传递标题选项.所以第二次代替

Checking the jQuery UI Dialog documentation you should have noted that you could simply pass in an title option. So the second time instead of

$('#dialog-confirm').attr("title", "Message");
$('#dialog-confirm').html(dialogMessage);
$('#dialog-confirm').dialog({
  resizable: false,
  height:    125,
  width:     300,
  ...
});

只需使用

$('#dialog-confirm').html(dialogMessage);
$('#dialog-confirm').dialog({
  resizable: false,
  height:    125,
  width:     300,
  ...
  "title", "Message" //NEW!
});

这篇关于使用另一个对话框的功能更改jQuery-UI对话框的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆