Select 没有 id 的内部元素 by JQuery

Select inner element with no id by JQuery

假设我有这个 div 块:

<div id="some_id" style="display: none;">
    <form action="someAction" method="post">
        <input type="hidden" name="some-name" value="some-value">
    </form>
</div>

我需要 select 这个 div 里面的 form。我可以通过 $('#some_id') select div 但是当我尝试通过 $('#some_id').find('form') (或 get select form$('#some_id:form')) 我收到此错误:

Uncaught TypeError: $(...).find is not a function

任何可能的解决方案?

你不想要 : 到 select 你想要的 child >

您的 select 或应如下所示:

$('#some_id > form')

还要确保包含 jQuery,您的代码似乎找不到它。

您的尝试没有任何问题,前提是 jQuery 已正确包含在您的页面中并且您使用 $jQuery 正确引用它(如果它在 noConflict 中)模式。

console.log(
  $('#some_id').find('form').get()
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="some_id" style="display: none;">
    <form action="someAction" method="post">
        <input type="hidden" name="some-name" value="some-value">
    </form>
</div>