Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.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 需要切换使用ajax动态添加的表行_Jquery_Html - Fatal编程技术网

Jquery 需要切换使用ajax动态添加的表行

Jquery 需要切换使用ajax动态添加的表行,jquery,html,Jquery,Html,每次单击链接时,它都会在其所在的当前行之后添加一个表行 $("#row"+id+"").after("<tr class='more-info' id='open"+id+"'><td colspan='13' class='mbg'>"+ html +"</td></tr>"); $(“#行”+id+”)。在(“+html+”)之后; 每次单击链接时,它都会添加另一行,并具有相同的确切信息。当我再次单击它时,我希望它做的是隐藏该行 我原以为追

每次单击链接时,它都会在其所在的当前行之后添加一个表行

$("#row"+id+"").after("<tr class='more-info' id='open"+id+"'><td colspan='13' class='mbg'>"+ html +"</td></tr>");
$(“#行”+id+”)。在(“+html+”)之后;
每次单击链接时,它都会添加另一行,并具有相同的确切信息。当我再次单击它时,我希望它做的是隐藏该行

我原以为追加.slideToggle()(如下)会起作用,但事实并非如此

$("#row"+id+"").after("<tr class='more-info' id='open"+id+"'><td colspan='13' class='mbg'>"+ html +"</td></tr>").slideToggle();
$(“#行”+id+”)。在(“+html+”)之后。滑动切换();

感谢您提供的任何帮助

因为您没有选择所创建的元素,所以链接不会起任何作用。您可以做的是选择下一个
tr
元素并隐藏。我猜您可能也不想再创建一行

.click(function(){
    if ($("#row" + id ).next('#open'+id).length > 0) {   // <-- check if there is a next row
        $("#row" + id ).next('#open'+id).slideToggle(); // <-- if there is just toggle next row
    } else {
        $("#row" + id + "").after("<tr class='more-info' id='open" + id + "'><td colspan='13' class='mbg'>testing</td></tr>");
        // else add new row
    }
});
。单击(函数(){

if($(“#row”+id).next(“#open”+id).length>0){/下面是一个示例,说明如何使对象在单击时可以“滑动切换”:

$("#idToHide").click(function(){
   $(this).slideToggle();
});
说明:首先需要附加一个单击处理程序。您可以执行此jQuery的单击功能。单击处理程序可以访问使用
this
单击的元素。要隐藏元素,只需使用jQuery--
$(this)
--选择它,然后使用
slideToggle()


示例:

这不起作用。您不想显示每一行中的多行是正确的。@Brad您可以发布一些html标记吗?如果有任何错误,请检查控制台,这会有所改进。我将id更改为data student=“43”,并检索id var id=$(this.data('student'));我注意到,在每个链接上单击两次链接后,单击才起作用。具有#行初始长度的内容?第一次单击将只添加新行。第二次单击将开始第一次滑动切换。我的错误是,我在css中显示:无;有关详细信息,已修复。谢谢!