Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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:Get row by tr';id';_Jquery - Fatal编程技术网

jQuery:Get row by tr';id';

jQuery:Get row by tr';id';,jquery,Jquery,嘿,我正在尝试访问特定的行。我有我不想得到的tr的id属性 我的桌子看起来像这样: <tbody role="alert" aria-live="polite" aria-relevant="all"> <tr id="1" class="odd"> <td class=" sorting_1">bla</td> </tr> <tr id="3" class="even">

嘿,我正在尝试访问特定的行。我有我不想得到的tr的id属性

我的桌子看起来像这样:

<tbody role="alert" aria-live="polite" aria-relevant="all">
    <tr id="1" class="odd">
        <td class=" sorting_1">bla</td>
    </tr>
    <tr id="3" class="even">
        <td class=" sorting_1">hej</td>
    </tr>
    <tr id="4" class="odd row_selected">
        <td class=" sorting_1">sdf</td>
    </tr>
    <tr id="8" class="even">
        <td class=" sorting_1">testgfdgvcxbvcbcv</td>
    </tr>
    <tr id="9" class="odd">
        <td class=" sorting_1">testgfdgvcxbvcbcvfdgsgfdgdfs</td>
    </tr>
</tbody>

布拉
嘿
自卫队
TestGFDGvCxBVCv
testgfdgvcxbvcbcvfdgsgfdgdfs
这里我需要进入
但是我不知道如何访问它。

好吧,你通常应该避免只使用数字id(除非你使用100%的HTML5!)。你应该明确地确保id在你的页面上是唯一的

但是您应该能够使用jquery选择器

$('#1')
假设您没有使用HTML5,那么您应该更改标记以使用更标准的ID:

<tbody role="alert" aria-live="polite" aria-relevant="all">
    <tr id="row1" class="odd">
        <td class=" sorting_1">bla</td>
    </tr>
    <tr id="row3" class="even">
        <td class=" sorting_1">hej</td>
    </tr>
    ...

您可以使用

$("#ID")
所以你的情况是

$("#1")

这将返回底层HTML元素的jQuery对象,在您的例子中是tr元素。

id不应该以数字开头……这真的是id吗?id在整个页面上应该是唯一的。@Th0rndike:在HTML5中,id可以以数字开头。根据您的“答案”关闭此项假设询问者的id是唯一的。你认为这可以信赖吗?@JanDvorak-根据我看到的标记,是的。恐怕我通过ESP查看OP其余代码的能力有点有限;)我猜是因为页面上没有id为
id
的元素,或者因为答案可能会批评提问者,但这可能是最简单的jQuery问题,可以使用入门指南轻松回答。我想我们永远也不会知道
$("#1")