我正在尝试寻找一种方法来提醒没有类、名称或 ID 的 p 标记的内容。它是一个名为“问题”的标签的子项,所以我想我可以直接进入它。父标签下有 2 个 p 标签,我要找的是第 2 个。当我运行它时,它返回 null。我不明白为什么,因为我是 JQuery 的新手,感谢您的帮助。
alert($('#question').find('p').first().next().html());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<td id="question">
<p>First</p>
<p>This is the one I want</p>
</td>
最佳答案
您的 javascript 没问题。问题出在您的 HTML 上。您可能忘记将其包装在表格和 tr 中:
alert($('#question').find('p').first().next().html());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td id="question">
<p>First</p>
<p>This is the one I want</p>
</td>
</tr>
</table>
问题中的代码从什么时候开始不起作用 <td>
没有 <table>
和 <tr>
然后它就像没有<td>
一样呈现:
<p>First</p>
<p>This is the one I want</p>
关于javascript - JQuery 返回 Null .next(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34323823/