Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 引用div的id_Javascript_Jquery_Arrays - Fatal编程技术网

Javascript 引用div的id

Javascript 引用div的id,javascript,jquery,arrays,Javascript,Jquery,Arrays,我试图引用变量thisId中div表行的id。当我console.log(thisId)时,它表示thisId是未定义的。我做错了什么 $('.deleteButton').click(function(){ var thisId = $(this).parent().parent().id; for (var i = 0; i < tableData.length; i++) { if (tableData[i].rowValue === thisId)

我试图引用变量
thisId
中div表行的
id
。当我
console.log(thisId)
时,它表示
thisId
未定义的
。我做错了什么

$('.deleteButton').click(function(){
    var thisId = $(this).parent().parent().id;
    for (var i = 0; i < tableData.length; i++) {
        if (tableData[i].rowValue === thisId) {
            tableData.splice(thisId, 1);
        }
    }
    $(this).parent().parent().remove();
});
}
}
$('.deleteButton')。单击(函数(){
var thisId=$(this.parent().parent().id;
对于(var i=0;i
HTML

“”+
"" +
“”+tableData[i]。textInput+”

”+ "" + "" + “”+tableData[i]。perIntervalInput+”

”+ "" + "" + “”+表格数据[i]。放射性输入+”

”+ "" + "" + “删除”+ "" + ""
因为您使用的是jQuery,所以可以使用:

var thisId = $(this).parent().parent().attr('id');

但是您的HTML并不是在这里向我们显示您实际引用的内容,以及您是否正确引用了它,因此可能还有其他原因。

ID是一个属性,因此可以通过函数进行引用

var thisId = $(this).parent().parent().attr("id");

这将引用的HTML在哪里?
.id
是DOM元素的属性,而不是jQuery。这是.attr或.prop的副本,似乎对我的工作没有帮助issue@germz所以
var thisId=$(this).closest('[id]')[0].id
var thisId=$(this).closest('[id]').attr('id')
或其他任何内容,但您的问题仍然未被注意。attr也是,结果相同。正如其他人所提到的,您需要扩展您的问题。我们需要查看您正在使用的HTML以及它是如何引用您的JS的。只是添加了HTML(因为它被附加了),如果上面的代码仍然不起作用,那么您的脚本似乎还存在其他问题。作为检查,请尝试
console.log($(this.parent().parent().get(0.outerHTML))
并查看它是否确实是您期望的代码。
var thisId = $(this).parent().parent().attr("id");