单击控制台中的按钮不起作用 [英] Click on a button in the console doesn't work
问题描述
我有一个更改页面的按钮,但是当我想用控制台单击它时,它不起作用.但是用鼠标它可以工作.
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屋!