Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.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 如果按钮不在a<;tr>;要素_Javascript_Jquery - Fatal编程技术网

Javascript 如果按钮不在a<;tr>;要素

Javascript 如果按钮不在a<;tr>;要素,javascript,jquery,Javascript,Jquery,只有当按钮不在tr内时,我才想执行if条件。这是我的密码: if (!$("tr").hasClass('hidebutton')) { var OriginalContent = $("#tabletask tr[data-id='" + parrentid + "'] > td:first-child").text(); $("#tabletask tr[data-id='" + parrentid + "'] > td:first-child").html("&

只有当
按钮不在
tr
内时,我才想执行
if
条件。这是我的密码:

if (!$("tr").hasClass('hidebutton')) {
    var OriginalContent = $("#tabletask tr[data-id='" + parrentid + "'] > td:first-child").text();
    $("#tabletask tr[data-id='" + parrentid + "'] > td:first-child").html("<button class=hidebutton>-</button> " + OriginalContent + " ");
}
if(!$(“tr”).hasClass('hidebutton')){
var OriginalContent=$(“#tabletask tr[data id='”+parrentid+“]>td:first child”).text();
$(“#tabletask tr[data id=”+parrentid+”]>td:first child”).html(“-”+OriginalContent+”);
}

但它不起作用。
如果
条件一直在执行。

我想我得到了一点你想要的

如果在“tr”中找不到按钮,您似乎要创建一个按钮,对吗?如果我是对的,你可以播放下面的片段

if(!$("tr button").hasClass("hidebutton")){
 $("#tabletask tr[data-id='" + parrentid + "'] > td:first-child").html('<button class="hidebutton">-</button> ' + OriginalContent);
}
if(!$(“tr按钮”).hasClass(“隐藏按钮”)){
$(“#tabletask tr[data id=”+parrentid+“]>td:first child”).html(“-”+OriginalContent);
}
顺便说一句,你好像在这条线上漏掉了什么

html("<button class=hidebutton>-</button> " + OriginalContent + " ");
html(“-”+原始内容+”);
您需要像下面的“隐藏按钮”一样封闭隐藏按钮

.html("<button class='hidebutton'>-</button> " + OriginalContent + " ");
.html(“-”+原始内容+”);

另一种方法是使用循环:

$("tr").each(function( index, value ) {
    if (!$(this).hasClass('hidebutton')){
        console.log($(this,"td:first-child").text());
    }
});

请看一下

可能重复的“对不起,我不明白”。请您解释一下,每当
按钮
不在
tr
中时,您想执行一些操作,对吗?这就像贴出的问题一样。您可以使用类似于
tr:not(:has(button))
的内容。