Javascript jquery-$(“myElement”).load(url)在插入到表行时不起作用

Javascript jquery-$(“myElement”).load(url)在插入到表行时不起作用,javascript,jquery,Javascript,Jquery,我有以下代码: $('#customerPaymentTable > tbody > tr').eq(index).after("<tr><td colspan='6'><center>" + $('#customerRecordForm').load(url) + "</center></td></tr>"); 我怎么才能让它工作呢?我真的需要插入那个div表单。请帮忙。提前谢谢。我觉得你在用一种奇怪的方式

我有以下代码:

$('#customerPaymentTable > tbody > tr').eq(index).after("<tr><td colspan='6'><center>" + $('#customerRecordForm').load(url) +  "</center></td></tr>");

我怎么才能让它工作呢?我真的需要插入那个div表单。请帮忙。提前谢谢。

我觉得你在用一种奇怪的方式

您应该在希望加载的数据显示的元素上调用load函数。load(url)函数没有返回任何输出值。它只是从url加载字符串并将其放入ID为customerRecordForm的元素中

所以当你创建一个

<div id="customerRecordForm"></div>
更多信息请点击此处:

在您的示例中,可能是这样的:

$('#customerPaymentTable > tbody > tr').eq(index).after("<tr><td colspan='6'><div id='customerRecordForm'></div></td></tr>");
$('#customerRecordForm').load(url);
$.ajax({
    url: url,
    dataType: "html",
    success: function(html){
        $('#customerPaymentTable > tbody > tr').eq(index).after("<tr><td colspan='6'><center>" +  html +  "</center></td></tr>");
    }
});
var $row = $('#customerPaymentTable > tbody > tr').eq(index);
$row.after('<tr><td colspan='6' class="foo"></td></tr>');
$(".foo", $row).load(url);
$('#customerPaymentTable>tbody>tr').eq(index).after(“”);
$('#customerRecordForm')。加载(url);

我觉得你在以某种奇怪的方式使用它

您应该在希望加载的数据显示的元素上调用load函数。load(url)函数没有返回任何输出值。它只是从url加载字符串并将其放入ID为customerRecordForm的元素中

所以当你创建一个

<div id="customerRecordForm"></div>
更多信息请点击此处:

在您的示例中,可能是这样的:

$('#customerPaymentTable > tbody > tr').eq(index).after("<tr><td colspan='6'><div id='customerRecordForm'></div></td></tr>");
$('#customerRecordForm').load(url);
$.ajax({
    url: url,
    dataType: "html",
    success: function(html){
        $('#customerPaymentTable > tbody > tr').eq(index).after("<tr><td colspan='6'><center>" +  html +  "</center></td></tr>");
    }
});
var $row = $('#customerPaymentTable > tbody > tr').eq(index);
$row.after('<tr><td colspan='6' class="foo"></td></tr>');
$(".foo", $row).load(url);
$('#customerPaymentTable>tbody>tr').eq(index).after(“”);
$('#customerRecordForm')。加载(url);
jQuery.load()将不会返回有效的HTML块,而是返回jQuery对象。此外,jQuery.load()将内容异步加载到您调用它的元素中。当然不是你想要的

您必须在加载内容后注入html代码

$.get(url, function (response) {
    $('#customerPaymentTable > tbody > tr').eq(index)
        .after("<tr><td colspan='6'><center>" + response +  "</center></td></tr>");

});
$.get(url、函数(响应){
$('#customerPaymentTable>tbody>tr').eq(索引)
.在(“+响应+”)之后;
});
jQuery.load()将不会返回有效的HTML块,而是返回jQuery对象。此外,jQuery.load()将内容异步加载到您调用它的元素中。当然不是你想要的

您必须在加载内容后注入html代码

$.get(url, function (response) {
    $('#customerPaymentTable > tbody > tr').eq(index)
        .after("<tr><td colspan='6'><center>" + response +  "</center></td></tr>");

});
$.get(url、函数(响应){
$('#customerPaymentTable>tbody>tr').eq(索引)
.在(“+响应+”)之后;
});

问题是因为
$(“#customerRecordForm”).load(url)
将使用url中的HTML填充
#customerRecordForm
元素,然后返回jQuery对象,而不是作为字符串的HTML

你有两个选择。首先,您可以更改逻辑,从AJAX调用中获取所需的HTML,然后将其插入表单元格,如下所示:

$('#customerPaymentTable > tbody > tr').eq(index).after("<tr><td colspan='6'><div id='customerRecordForm'></div></td></tr>");
$('#customerRecordForm').load(url);
$.ajax({
    url: url,
    dataType: "html",
    success: function(html){
        $('#customerPaymentTable > tbody > tr').eq(index).after("<tr><td colspan='6'><center>" +  html +  "</center></td></tr>");
    }
});
var $row = $('#customerPaymentTable > tbody > tr').eq(index);
$row.after('<tr><td colspan='6' class="foo"></td></tr>');
$(".foo", $row).load(url);

问题是因为
$('#customerRecordForm').load(url)
将使用url中的HTML填充
#customerRecordForm
元素,然后返回jQuery对象,而不是作为字符串的HTML

你有两个选择。首先,您可以更改逻辑,从AJAX调用中获取所需的HTML,然后将其插入表单元格,如下所示:

$('#customerPaymentTable > tbody > tr').eq(index).after("<tr><td colspan='6'><div id='customerRecordForm'></div></td></tr>");
$('#customerRecordForm').load(url);
$.ajax({
    url: url,
    dataType: "html",
    success: function(html){
        $('#customerPaymentTable > tbody > tr').eq(index).after("<tr><td colspan='6'><center>" +  html +  "</center></td></tr>");
    }
});
var $row = $('#customerPaymentTable > tbody > tr').eq(index);
$row.after('<tr><td colspan='6' class="foo"></td></tr>');
$(".foo", $row).load(url);

OMG
?这已经被永远弃用了…天哪?这已经被永远地否决了…非常感谢你的回答,特别是解释。非常感谢你的回答,特别是解释。