本文介绍了使用JQuery单击特定的提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下方法单击提交"按钮:
I am clicking a submit button using this:
$('input[type=submit]').click();问题是我的页面上有1个以上的提交按钮,因此我需要定位一个特定的提交按钮.
The problem is that I have more that 1 submit button on my page so I need to target a specific submit button.
我该怎么办?
推荐答案如果知道submit输入的数量以及想要触发click的哪个(按顺序),则可以使用nth-child()以它为目标的语法.或为每个ID添加一个ID或一个类,以将它们彼此隔离.
If you know the number of submit inputs and which one (in order) you want to trigger a click on then you can use nth-child() syntax to target it. Or add an ID or a class to each one that separates them from the other.
通过索引选择元素:
$('input[type="submit"]:nth-child(1)').trigger('click');//selects the first one $('input[type="submit"]:nth-child(2)').trigger('click');//selects the second one $('input[type="submit"]:nth-child(100)').trigger('click');//selects the 100th one实际上有几种方法可以做到这一点,包括使用.eq(): api.jquery/eq
There are actually several ways to do this including using .eq(): api.jquery/eq
通过其ID选择元素:
<input type="submit" id="submit_1" /> <input type="submit" id="submit_2" /> <input type="submit" id="submit_100" /> <script> $('#submit_100').trigger('click'); </script>请注意,.click()是.trigger('click')的缩写.
更多推荐
使用JQuery单击特定的提交按钮
发布评论