jQuery未定义的值

3
我是一位新手使用jQuery,同时也在使用jQuery Datatables遇到了一个问题,我相信这个问题很简单但我无法解决。处理程序.iframe.iframe2.iframe3都工作正常,问题出在.iframe4上。
我成功获取了.iframe.iframe2.iframe3data [0]的值,但我无法在.iframe4中显示其值。现在我只需要在.iframe4中显示data[0]的值,但我得到了JS错误,说该值未定义。以下是我的代码:
<script type="text/javascript" language="javascript" class="init">
    $(document).ready(function() {
        var table = $('#example').DataTable( {
        //  bPaginate: false,
        "columnDefs": [ {
            "targets": -1,
            "data": null,
            "defaultContent": "<input type='image' src='delete.png' id='button' >"
        },
        {
            "targets": -2,
            "data": null,
            "defaultContent": "<input type='image' src='edit.png' id='button' >"
        },
        {
            "targets": -3,
            "data": null,
            "defaultContent": "<input type ='image' src='edit.png' id='button' >"
        },
        {
            "targets": -4,
            "data": null,
            "defaultContent": " "
        }
        ],
        "order": [[ 0, "desc" ]]
    } );
        $('#example tbody').ready(function(){
           var data = table.row( $(this).closest('tr') ).data();
           $(".iframe4").ready(function()
           {
               $(".iframe4").text(data[0]);
           });
       });
        $('#example tbody').on('click', 'input', function(){
         var data = table.row( $(this).closest('tr') ).data();
         $(".iframe").colorbox({maxWidth:'95%', maxHeight:'95%', href:"session_edit.php?ID="+data[0]});
         $(".iframe3").colorbox({href:"delete.php?ID="+data[0]});
     });
        $('#example tbody').on('click', 'input', function(){
           var data = table.row( $(this).closest('tr') ).data();
           $(".iframe2").ready(function()
            {window.location.replace("record_dt.php?ID="+data[0])});
       });
    });
</script>

.iframe4是什么?data[0].iframe4未定义吗?你的数据长什么样? - markpsmith
1个回答

0

你的代码中有一个拼写错误。很可能这是你想要做的:

$('#example tbody').on('click', 'input', function () {
    var data = table.row($(this).closest('tr')).data();
    $(".iframe4").ready(function () {
        $(".iframe4").text(data[0]);
    });
});

然而,在单击事件中附加事件处理程序而不先分离它是一个糟糕的选择。我相信你可以使用下面的代码代替。

$('#example tbody').on('click', 'input', function () {
    var data = table.row($(this).closest('tr')).data();
    $(".iframe4").text(data[0]);
});

同样适用于您的其他点击处理程序。


抱歉,但它也不能正常工作。我所需要的只是显示data[0]的值。 - elstiv

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接