gpt4 book ai didi

javascript - jQuery 未定义值

转载 作者:行者123 更新时间:2023-12-01 01:43:17 25 4
gpt4 key购买 nike

我是 jQuery 新手,在使用 jQuery Datatables 时遇到了这个问题,我认为这个问题很简单,但我无法弄清楚。处理程序 .iframe.iframe2.iframe3 工作正常,问题是 .iframe4

我设法在 .iframe.iframe2.iframe3 中获取 data[0] 的值code> 但我无法在 .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>

最佳答案

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

$('#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]);
});

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

关于javascript - jQuery 未定义值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32943079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com