简体   繁体   中英

Submit button clicked via javascript doesn't “submit” in IE6

For reasons I won't go into we need to click a submit button (as opposed to a plain button) via Javascript.

We do this by getting a handle to the submit button, then executing the .click() method on this button. This works perfectly in FireFox, but in IE6 it only works partially.

The button receives the click, and code associated with the buttons "onClick" event fires (we can observe this by watching the server-side code in the debugger) however, the page never "refreshes" the way it should when clicking a "submit" button.

Since this works in FireFox, we assume it is yet another IE6 bug, but I'm not having any luck finding a work-around. We can't simply refresh the page directly because we need it drawn as though it were drawn from the submit button POST request.

Wouldn't it be easier to get a reference to the form element and fire the submit event?

var form = document.forms[0];
form.submit();

I have the same issue in ASP.net. We must "click" the button because there is more that happens in ASP.net with a form than just the normal .submit() on the form. It has to know which button you clicked so it can match it up to the Click event on the server-side for that button.

尝试使用setTimeout将点击延迟1毫秒。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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