IE 6 and the multiple button elements all sending their name & values

别说谁变了你拦得住时间么 提交于 2019-12-01 09:47:52

I found a solution at http://www.codecomments.com/JavaScript/message756646.html

All credit to the author on that page.

Per request, here is the code

function buttonfix(){
var buttons = document.getElementsByTagName('button');
for (var i=0; i<buttons.length; i++) {
buttons[i].onclick = function () {
for(j=0; j<this.form.elements.length; j++)
if( this.form.elements[j].tagName == 'BUTTON' )
this.form.elements[j].disabled = true;
this.disabled=false;
}
}
}
window.attachEvent("onload", buttonfix);

This is a known bug in Internet Explorer.

http://www.dev-archive.net/articles/forms/multiple-submit-buttons.html describes a workaround that does not depend on JavaScript.

It boils down to "Use <input> and don't design your buttons to need anything other than simple text for their labels".

Walter Rumsby

An solution is to use <input type="button"> and <input type="submit"> in your page instead of <button type="button"> and <button>.

Update: if you change your button elements to input elements you should be able to find them using jQuery with the following selector:

var buttons = $('input[type=submit], input[type=button]');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!