使用JQuery单击特定的提交按钮

编程入门 行业动态 更新时间:2024-10-12 12:33:49
本文介绍了使用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单击特定的提交按钮

本文发布于:2023-11-11 05:30:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577513.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单击   按钮   JQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!