单击控制台中的按钮不起作用 [英] Click on a button in the console doesn't work

查看:223
本文介绍了单击控制台中的按钮不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个更改页面的按钮,但是当我想用控制台单击它时,它不起作用.但是用鼠标它可以工作.

I have a button to change page but when I want to click on it with the console it doesn't work. But with the mouse it works.

这是个笨蛋: http://plnkr.co/edit/shr2xhNHzcYwTBPJlisQ?p=preview

我在控制台中执行此操作:$('#language_us').click();$('#language_fr').click();,但它不会更改页面.

And I do this in the console : $('#language_us').click(); or $('#language_fr').click(); but it doesn't change page.

你有个主意吗? 谢谢

推荐答案

您正在使用锚点<a>,而不是按钮<button>.

You are using anchors <a> and not button <button>.

要触发单击<a>,您需要使用DOM元素,jQuery对象$()不起作用.

To fire click on <a> you need to use the DOM element, jQuery object $() does not work.

使用

$('#language_us')[0].click();


.trigger().click()触发明确定义的点击处理程序.您需要本地点击事件,这是锚点的默认功能.因此,您需要使用HTMLElement对象.


.trigger() or .click() triggers a click handler defined explicitly. You need the native click event which is the default functionality of an anchor. So you need to use HTMLElement Object.

如果您会写:

$('#language_fr').click(function(){
  alert('..')
})

The

$('#language_fr').click()

会开除alert().

这篇关于单击控制台中的按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆