-2

我在点击的ID中选择ap标签时遇到了一些问题,代码如下;

<tbody>
    <tr id="test1">
    <p>
        Some random text that should show up in the dialog.
    </p>
        <td>test</td>
        <td>test</td>
    </tr>
    ... the rest of the tr's are identical, nothing else to see here.
 </tbody>


$('#test1, #test2, #test3, #test4').click(function(){
    $(this 'p').dialog();
});

现场测试;http://team-blandsaft.no-ip.org/

最好习惯在 stackoverflow 编辑器中编写一些代码。

4

2 回答 2

5

使用.find()

$(this).find('p').dialog();

或者您可以使用上下文选择器

$('p',this).dialog(); 

在内部使用 find 方法

<p>正如其他人所提到的,您的 html 无效<tr>

来自tr 的MDN 文档

允许的内容:零个或多个<td><th>元素,或它们的混合

于 2013-04-12T20:48:22.897 回答
0
$('#test1, #test2, #test3, #test4').click(function(){
    $(this).children('p').dialog();
});
于 2013-04-12T22:52:15.577 回答