【问题标题】:How to call callback function of jquery html() method如何调用jquery html()方法的回调函数
【发布时间】:2015-05-01 03:03:18
【问题描述】:

以下是我的 jquery 代码,它执行以下操作:

  1. 加载内容表单 URL 并填写 DIV。
  2. 将数据绑定到html表单中。 问题:第一次绑定正确的数据,每次调用后,它只是加载空表单(以及通过BindForm函数调用的未填充数据,如下所示。)

当我尝试将 - tag.html 替换为 $("#div").load(url,function(){}) 时,它可以工作,但是使用下面的代码不起作用。

现在,我无法将实现更改为使用 load,但是,以下代码中的任何替代方案或解决方案都会有所帮助。

基本上,我需要$("<div id=" + diaolgID + "></div>") 行保持原样,然后在其中加载对话框。

var tag = $("<div id=" + diaolgID + "></div>");
$.ajax({
    url: url,
    cache: false,
    success: function(data) {
        var htmlContainerObject = tag.html(data);

        htmlContainerObject.dialog({
            modal: true,
            hide: {
                effect: "none",
                duration: 150
            },
            show: {
                effect: "none",
                duration: 150
            },
            title: title,
            width: 950,
            height: 'auto'
        }).dialog('open');

        BindForm();
    }
});

【问题讨论】:

  • 您是否曾经将tag 附加到DOM
  • 没有。它只是在对话框中打开。

标签: javascript jquery html ajax jquery-dialog


【解决方案1】:

将您的第一行更改为:

var tag = $('<div id="' + diaolgID + '"></div>').appendTo('body');

【讨论】:

    猜你喜欢
    • 2012-05-05
    • 2012-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-08
    • 1970-01-01
    • 2012-08-06
    • 2021-08-13
    相关资源
    最近更新 更多