Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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
Jquery:不从html表中删除行_Jquery_Html Table_Row_Removeclass - Fatal编程技术网

Jquery:不从html表中删除行

Jquery:不从html表中删除行,jquery,html-table,row,removeclass,Jquery,Html Table,Row,Removeclass,我有一个html表,需要根据函数传递的ID删除一些行 这是我的密码: <html> <script> function myfunc(){ var dat ="6|21|22|"; // this string is a dynamic string coming // from another function. I've hardcoded it

我有一个html表,需要根据函数传递的ID删除一些行

这是我的密码:

<html>
    <script>
    function myfunc(){
        var dat ="6|21|22|"; // this string is a dynamic string coming 
                             // from another function. I've hardcoded it 
                             // for clarity
        var aryDat0 = dat.split('|');
        //delete empty elements
        var aryDat = aryDat0.filter(function(v){return !!v}); 
        for (var i = 0, l = aryDat.length; i <l; i++) {
          $( "'#" + aryDat[i] + "'" ).remove();
        }
    }
    </script>
    <table name="mytab" border="1px">
        <tr id="6"> 
            <td>6</td>
            <td>ada</td>
        </tr>
        <tr id="21">
            <td>21</td>
            <td>eda</td>
        </tr>
        <tr id="22">
            <td>22</td>
            <td>ida</td>
        </tr>
    </table>
    <input type="button" value="test" 
           onclick="javascript:myfunc(); return false;">
</html>
为什么?? 如果不是:

$( "'#" + aryDat[i] + "'" ).remove();
我有:

$('#21').remove();
它工作得很好

此错误未捕获错误:语法错误,无法识别的表达式:“#6”明确指出,
$(“#6”)是无效的Jquery选择器

试试看


只需将id值连接到#


+”
当然非常有用。哈哈哈,太棒了!非常感谢!我马上就接受你的回答。再次感谢@戴斯特罗伊·欧普先生,请不要注意调试代码的第一种方法是编写干净的代码!为了更好的可读性,我编辑了你的帖子代码!
$('#21').remove();
$( "#" + aryDat[i]).remove();
 $( '#' + aryDat[i]  ).remove();