Disabling button with [removed] FF vs IE

2019-05-11 12:22发布

I have a row of buttons, which all create a pdf file which I want to open in a new tab. This way the button page stays on top, and the pdf's open to get printed. To prevent clicking a button twice I disable the button, like this (I use python):

<input type='submit' value='Factureren' name='submitbutton' id='%s'
onclick="javascript:document.getElementById('%s').disabled=true; 
document.getElementById('%s').className='button_disabled';"> % ((but_id,) *3)

In FF3 this works fine, i.e. the form is submitted, the script executed and then the button disables. In IE the button just disables, but the form script isn't executed.

Is there a solution to this IE problem?

8条回答
我只想做你的唯一
2楼-- · 2019-05-11 12:45

It is easier to do:

    <input type='submit' value='Factureren' name='submitbutton' id='%s' 
onclick="this.disabled=true; this.className='button_disabled';"> % ((but_id,) *3)

I don't know if this solves your problem but it is what I would do in a case like this. I think you don't need "javascript:" anyway.

查看更多
做自己的国王
3楼-- · 2019-05-11 12:48

You can try using a normal button and triggering the form submit() function in the onclick event:

<input type="button" value="Factureren" name="submitbutton" 
onclick="this.disabled=true; this.className='button_disabled'; this.form.submit();">
查看更多
够拽才男人
4楼-- · 2019-05-11 12:50

It is easy: a disabled submit button do not submit a form in IE. Consider to restructure your code:

  • Use a regular button, disable it, and call form.submit() from its handler.
  • Do not disable the button in its "onclick", but save it, and do it in form's onsubmit.
查看更多
Rolldiameter
5楼-- · 2019-05-11 12:51

Instead of controlling the div, why not control the actual submit button? This works universally in all browsers I have tested (IE6+ FF1+ and Safari)

function toggleSubmit(){  
    frm=document.forms[0]
    if(frm.submit.disabled==true){
        frm.submit.disabled=false;
    }else{
       frm.submit.disabled=true;
    }
 }

Then on the button all you have to call is

<input type='submit' value='Factureren' name='submitbutton'
onclick="toggleSubmit();false;"> % ((but_id,) *3)
查看更多
霸刀☆藐视天下
6楼-- · 2019-05-11 12:54

Maybe try to attach the handler to the onsubmit event of the form instead of the click of the button? That would also then work if the user pressed ENTER instead of clicking your button.

查看更多
看我几分像从前
7楼-- · 2019-05-11 12:54

onclick="this.disabled='disabled'; this.form.submit();" works perfectly for me

查看更多
登录 后发表回答