当我单击标签并向这些输入字段输入一些值时,我试图查找所有输入字段
我使用console.log检查在我关闭弹出窗口后会发生什么。
像这里,我正在使用var字段= $(this).find('input[type="hidden"]')
-我应该使用find
它,因为它不是遍历顶部而是底部
它发现的只是锚标记,而不是所有隐藏字段
我认为我不需要each
为此目的
<a href="tag"></a>
<input value="1" type="hidden" class="myclass">
<input value="1" type="hidden" class="myclass">
<input value="1" type="hidden" class="myclass">
您可以仅使用带有正确选择器的.nextAll()
method'input[type="hidden"]'
,它将inputs
在a
元素之后选择所有内容:
$(this).nextAll('input[type="hidden"]').each(function() {
$(this).prop("type", "text")
});
演示:
$("#myLink").click(function() {
$(this).nextAll('input[type="hidden"]').each(function() {
$(this).prop("type", "text")
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<a id="myLink" href="#">Click me</a>
<input value="1" type="hidden" class="myclass">
<input value="1" type="hidden" class="myclass">
<input value="1" type="hidden" class="myclass">
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句