简体   繁体   English

button.click()在IE11下不起作用

[英]button.click() does not work under IE11

I have created a jqx menu with the following script: 我用以下脚本创建了一个jqx菜单:

<ul style='width: 200px;'>
    <li onclick="logOffButton.click();">Sign off</li>
</ul>

So I'd like to trigger a click event on the "logOffButton" once the user clicked to the menu item. 因此,一旦用户单击菜单项,我想在“ logOffButton”上触发单击事件。 The code for the button: 该按钮的代码:

<form id="logOff" action="www.example.com" method="get">
    <input type="button" id="logOffButton" placeholder="Are you sure you want to log off?" onclick="UserConfirm(this)" style="display: none;" />
</form>

So once the button click is triggered, it creates an JS alert message and if the user press OK it submits the form. 因此,一旦触发了按钮单击,它就会创建一个JS警报消息,如果用户按下OK,它将提交表单。

The problem is that while this works fine under Chrome and Firefox, it doesn't work under IE11. 问题是,尽管在Chrome和Firefox上可以正常工作,但在IE11下却无法工作。

The full code can be found here: http://jsfiddle.net/82xhy/1/ 完整的代码可以在这里找到: http : //jsfiddle.net/82xhy/1/

try this:- 尝试这个:-

replace <li onclick="logOffButton.click();">Sign off</li> with <li onclick="logOffButton.click();">Sign off</li>替换为

 <li onclick="$('#logOffButton').click();">Sign off</li>

Demo 演示

Basically your code is wrong, and it works on chrome and other browsers because they try to understand what you mean. 基本上,您的代码是错误的,并且可以在chrome和其他浏览器上使用,因为它们试图理解您的意思。 logOffButton.click() points to nothing, so ie being so bad and all does not understand what you mean. logOffButton.click()指向任何内容,即太糟糕了,所有人都无法理解您的意思。 $('#logOffButton').click(); or document.getElementById('logOffButton'); document.getElementById('logOffButton'); will fix this problem because they both point exactly to where you need to, and don't require the browser to 'guess' 将解决此问题,因为它们都精确指向您需要的位置,并且不需要浏览器“猜测”

Both $('#logOffButton') and document.getElementById('logOffButton'); $('#logOffButton')document.getElementById('logOffButton'); are element selectors, first is jquery and second one is javascript. 是元素选择器,第一个是jquery,第二个是javascript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM