Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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 对于这个.id.slice(-1),我的代码将很快停止工作_Jquery - Fatal编程技术网

Jquery 对于这个.id.slice(-1),我的代码将很快停止工作

Jquery 对于这个.id.slice(-1),我的代码将很快停止工作,jquery,Jquery,我刚刚发现这个.id.slice(-1)只能在id 0到9之间工作 在它停止工作之前,我需要一个新的替代品。这就是我所拥有的 $("a.toggle_showhide_links").click(function() { $("#showhide" +this.id.slice(-1)).slideToggle(400); }); 这是一个至少运行5次的循环 <tr> <td><a id='link-".$x."' class='toggle_show

我刚刚发现这个.id.slice(-1)只能在id 0到9之间工作

在它停止工作之前,我需要一个新的替代品。这就是我所拥有的

$("a.toggle_showhide_links").click(function() {
  $("#showhide" +this.id.slice(-1)).slideToggle(400);
});
这是一个至少运行5次的循环

<tr>
    <td><a id='link-".$x."' class='toggle_showhide' href='#!'>CLICK</a></td>
</tr>
<tr id='showhide-".$x."' style='display:none;'>
    <td style='border:1px solid black;' colspan='2'>
           <!-- Hideable contents-->
    </td>
</tr>";

如果ID始终遵循模式
链接-
显示隐藏-
,那么从另一个ID生成一个ID的非常简单的方法是替换
链接
显示隐藏
部分:

$('#' + this.id.replace('link', 'showhide'))

$('#'+this.id.replace('link','showhide'))
怎么样?@FelixKling谢谢你,它能工作。我肯定我会花一整晚的时间来做,但是没有成功,但是你很快给了我一个解决方案。你能把它作为答案贴出来吗?
$('#' + this.id.replace('link', 'showhide'))