使用 jQuery 以编程方式单击 关联
我知道这个问题以前曾被问过,但在网上搜索后我似乎找不到直接的答案。
HTML
<a id=myAnchor href=index.php>
jQuery (这两者都不起作用)
$('#myAnchor').click();
或者
$('#myAnchor').trigger('click');
实现此目的最简单、最有效的方法是什么?
I know this question has been asked before, but after a search on the web I can't seem to find a straight forward answer.
the HTML
<a id=myAnchor href=index.php>
the jQuery (Both of these do not work)
$('#myAnchor').click();
or
$('#myAnchor').trigger('click');
What is the simplest and most efficient way to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
试试这个:
它对我有用。
Try this:
It works for me.
单击仅触发单击事件,而不是实际的“goto-the-links-href”操作。
您必须编写自己的处理程序,然后您的 $('#myAnchor').trigger('click'); 才能工作......
Click just triggers the click event / events not the actually "goto-the-links-href" action.
You have to write your own handler and then your $('#myAnchor').trigger('click'); will work...
将
onclick="window.location = this.href"
添加到元素。进行此修改后,它可以按预期行为进行
.click()
编辑。要对页面上的每个链接执行此操作,您可以添加以下内容:Add
onclick="window.location = this.href"
to your<a>
element. After this modification it could be.click()
ed with expected behaviour. To do so with every link on your page, you can add this:我尝试了上述几种解决方案,但它们对我不起作用。这是对我有用的页面的链接 自动点击链接
上面的链接有很多解决方案,这是对我有用的一个,
现在在
标签中,
复制粘贴上面的代码,然后单击
'Magic button'
按钮,您将被重定向到ErCafe.com
。I tried few of the above solutions but they didn't worked for me. Here is a link to the page which worked for me automatically click a link
Above link has many solutions and here's the one which worked for me,
Now within the
<script>
tags,Copy paste the above code and click on clicking the
'Magic button'
button, you will be redirected toErCafe.com
.我有类似的问题。试试这个
$('#myAnchor').get(0).click();
这对我有用I had similar issue. try this
$('#myAnchor').get(0).click();
this works for me如果您使用的是 jQuery,则可以使用
jQuery.trigger
http://api .jquery.com/trigger/示例
If you are using jQuery, you can do it with
jQuery.trigger
http://api.jquery.com/trigger/Example
尝试一下这个兼容性;
Try this for compatibility;