<head> <!--参考:http://illy.iteye.com/blog/1534276 --> <!-- http://y.dobit.top/Detail/10.html --> <!-- http://www.haorooms.com/post/js_setTimeout --> <!-- http://jun1986.iteye.com/blog/1136389 --> <script language="javascript"> /*function submitApprove(a0) { disabledButton(); MyPeriodicalExecuter(evt); } function disabledButton(){ var inputs = document.getElementsByTagName("button"); for(var i = 0;i<inputs.length;i++){ if(inputs[i].id.toLowerCase()=="test") inputs[i].disabled=true; } } function MyPeriodicalExecuter(evt){ succ.obj=evt; succ.loop=0; sh=setInterval(succ,1000); } function succ(){ var str="禁止连续点击," with(arguments.callee){ obj.value=str+"("+(loop++)+"/15)秒后再试"; if (loop > 5 ){ enabledButton(); obj.value=" 下载 "; clearInterval(sh); return; } } } function enabledButton(){ var inputs = document.getElementsByTagName("button"); for(var i = 0;i<inputs.length;i++){ if(inputs[i].id.toLowerCase()=="test") inputs[i].disabled=false; } }*/ /*function submitApprove(evt) { console.log('evt ' + evt); disabledButton(evt); console.log('evt execute'); MyPeriodicalExecuter(); //enabledButton(evt); } function disabledButton(evt){ //var inputs = document.getElementById(evt); var text = document.getElementById(evt); console.log('getElementById'); text.disabled=true; } function MyPeriodicalExecuter(){ //succ.obj=evt; succ.loop=0; console.log('111'); sh=setInterval(succ,1000); console.log('777'); } function succ(){ console.log('222'); with(arguments.callee){ console.log('333'); console.log('loop = '+loop); loop++; //obj.value=str+"("+(loop++)+"/15)retry"; if (loop > 5 ){ console.log('444'); enabledButton(); console.log('555'); //obj.value=" down "; clearInterval(sh); console.log('666'); return; } } } function enabledButton(){ console.log('enabledButton evt '); var text = document.getElementById("newtest1"); console.log('text getElementById newtest1'); text.disabled=false; }*/ function submitApprove(evt) { console.log('evt ' + evt); disabledButton(evt); console.log('evt execute'); MyPeriodicalExecuter(); //enabledButton(evt); } function disabledButton(evt){ //var inputs = document.getElementById(evt); var text = document.getElementById(evt); console.log('getElementById'); text.disabled=true; } function MyPeriodicalExecuter(){ succ.loop=0; console.log('111'); sh=setInterval(succ,1000); //sh=setTimeout(succ,1000); console.log('777'); } function succ(){ console.log('222'); with(arguments.callee){ console.log('333'); console.log('loop = '+loop); loop++; if (loop > 5 ){ console.log('444'); enabledButton(); console.log('555'); clearInterval(sh); //clearTimeout(sh); console.log('666'); return; } } } function enabledButton(){ console.log('enabledButton evt '); var text = document.getElementById("newtest1"); console.log('text getElementById newtest1'); text.disabled=false; } </script> <!--<script language="javascript">function submitApprove(a0){ console.log('aaaa'); window.open('https://www.baidu.com','newwindow')}</script>--> </head> <!--<body class="xg" onload="return _chain('_checkLoad(event)','Linit();',this,event)" onunload="_checkUnload(event)">--> <!--<button id="Test" title="测试" class="x7g" style="background-image:url(/OA_HTML/cabo/images/swan/btn-bg1.gif)" onclick="return _chain('javascript:submitApprove(this);','submitForm(\'DefaultFormName\',1,{\'evtSrcRowIdx\':\'\',\'evtSrcRowId\':\'\',event:\'testJSFunction\',source:\'Test\'});return false;',this,event,true)" type="button">测试</button> --> <!--<button id="test" title="测试" class="x7g" style="background-image:url(/OA_HTML/cabo/images/swan/btn-bg1.gif)" onclick="return _chain('downLoad(this)','submitForm(\'DefaultFormName\',1,{\'evtSrcRowIdx\':\'\',\'evtSrcRowId\':\'\',event:\'testJSFunction\',source:\'Test\'});return false;',this,event,true)" type="button">测试</button>--> <!--浏览器默认生成的源码--> <!--<button id="Test" title="测试" class="x7g" style="background-image:url(/OA_HTML/cabo/images/swan/btn-bg1.gif)" onclick="return _chain('javascript:submitApprove(this);','submitForm(\'DefaultFormName\',1,{\'evtSrcRowIdx\':\'\',\'evtSrcRowId\':\'\',event:\'testJSFunction\',source:\'Test\'});return false;',this,event,true)" type="button">测试</button>--> <!--<button id="FinSign" title="财务审核" class="x7g" style="background-image:url(/OA_HTML/cabo/images/swan/btn-bg1.gif)" onclick="javascript:submitApprove(this);submitForm('DefaultFormName',1,{'evtSrcRowIdx':'','evtSrcRowId':'',event:'finSignEvent',source:'FinSign'});return false;" type="button">财务审核</button>--> <!--<button id="testtest" title="测试" class="x7g" style="background-image:url(/OA_HTML/cabo/images/swan/btn-bg1.gif)" onclick="return _chain('javascript:submitApprove(this);','submitForm(\'DefaultFormName\',1,{\'evtSrcRowIdx\':\'\',\'evtSrcRowId\':\'\',event:\'testJSFunction\',source:\'Test\'});return false;',this,event,true)" type="button">测试 ceshi测试啊测试</button>--> <!--<button id="TestSbtn" title="" class="x7g" style="background-image:url(/OA_HTML/cabo/images/swan/btn-bg1.gif)" onclick="return _chain('javascript:submitApprove(this);','submitForm(\'DefaultFormName\',1,{\'_FORM_SUBMIT_BUTTON\':\'TestSbtn\'});return false',this,event,true)" type="submit">TestSbtn</button>--> <button id="test" title="测试" onclick="javascript:submitApprove(this);" type="button">测试</button> <button id="newtest" type="button" onClick="submitApprove(this.id)">newTest</button> <button id="newtest1" type="button" onClick="submitApprove(this.id)">newTest22</button> <input type="button" value="下载" /> </body>
以参数的形式获取elementId而不是直接在代码中写死。
<head> <!--参考:http://illy.iteye.com/blog/1534276 --> <!-- http://y.dobit.top/Detail/10.html --> <!-- http://www.haorooms.com/post/js_setTimeout --> <!-- http://jun1986.iteye.com/blog/1136389 --> <script language="javascript"> var buttonId ='buttonId'; function submitApprove(evt) { console.log('evt ' + evt); console.log('buttonId ' + buttonId); buttonId = evt; console.log('buttonId ' + buttonId); disabledButton(evt); console.log('evt execute'); MyPeriodicalExecuter(); //enabledButton(evt); } function disabledButton(evt){ //var inputs = document.getElementById(evt); var text = document.getElementById(evt); console.log('getElementById'); text.disabled=true; } function MyPeriodicalExecuter(){ succ.loop=0; console.log('111'); sh=setInterval(succ,1000); //sh=setTimeout(succ,1000); console.log('777'); } function succ(){ console.log('222'); with(arguments.callee){ console.log('333'); console.log('loop = '+loop); loop++; if (loop > 5 ){ console.log('444'); enabledButton(); console.log('555'); clearInterval(sh); //clearTimeout(sh); console.log('666'); return; } } } function enabledButton(){ console.log('enabledButton evt '); console.log('enabledButton buttonId ' + buttonId); var text = document.getElementById(buttonId); text.disabled=false; } </script> </head> <button id="test" title="测试" onclick="javascript:submitApprove(this);" type="button">测试</button> <button id="newtest" type="button" onClick="submitApprove(this.id)">newTest</button> <button id="newtest1" type="button" onClick="submitApprove(this.id)">newTest22</button> <input type="button" value="下载" /> </body>