2015-10-05 73 views
3

我是jQuery的新手,并使用jQuery Datatables我遇到了这个问题,我相信很简单,但我无法弄清楚。处理程序.iframe.iframe2.iframe3工作正常,问题是.iframe4jQuery未定义值

我设法得到.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> 
+0

什么是'.iframe4'?什么是未定义的 - 'data [0]'或'.iframe4'?你的数据是什么样的? – markpsmith

回答

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]); 
}); 

它也适用于您的其他点击处理程序。

+0

抱歉,但它不工作。我需要的只是显示数据的值[0] – elstiv