javascript jQuery 脚本自动点击链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7128369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 23:03:20  来源:igfitidea点击:

jQuery script to click automatically on a link

javascriptjquery

提问by BZink

My current code that i use is this:

我当前使用的代码是这样的:

<script type="text/javascript">
$(document).ready(function(){
$('#on_holiday').trigger('click');
});
</script>

How ever, this only works when the 'ID' is 'on_holiday' within the input form. I need this to work when I have another element within the form - The current 'ID' is:

但是,这仅在输入表单中的“ID”为“on_holiday”时才有效。当我在表单中有另一个元素时,我需要它来工作 - 当前的“ID”是:

<a href="#" data-reveal-id="on_holiday" class="side_link">Test</a>

My problem is when ever I add the element 'ID' to this link, it messes up the data-reveal-id and its cause. I need some sort of jQuery code that can click this link without the need to put the 'ID' field in.

我的问题是,当我将元素“ID”添加到此链接时,它会弄乱 data-reveal-id 及其原因。我需要某种可以单击此链接的 jQuery 代码,而无需输入“ID”字段。

Many thanks in advance.

提前谢谢了。

回答by Joseph Marikle

Tried

试过

$('[data-reveal-id="on_holiday"]').trigger('click');

or something of that sort?

或类似的东西?

回答by SideDishStudio

What about:

关于什么:

$('[data-reveal-id="on_holiday"]').trigger('click');

回答by BZink

Well you have a number of options. Take a look at the jQuery selectors page.

那么你有很多选择。查看 jQuery 选择器页面。

http://api.jquery.com/category/selectors/

http://api.jquery.com/category/selectors/

$("a").click(); //by tag.
$("a[href='#']").click(); //by tag with href property
$(".side_link").click(); //by class
$("div#someId a.side_link").click(); // This would work if the link was a child of a div with Id = someId