当前位置: 代码迷 >> Web前端 >> 让交付按钮返回后自动可用
  详细解决方案

让交付按钮返回后自动可用

热度:122   发布时间:2012-09-29 10:30:01.0
让提交按钮返回后自动可用

<input type="button" name="exportBtn" id="exportBtnId" value="导出Excel" class="button"
??????onclick="searchViewFixCardForBrushListForm.submit();this.blur();"/>

?

<script type="text/javascript">

function RestEnableButton(obj){?
?this.btnObj = (typeof obj=="string")?document.getElementById(obj):obj;
?if(window.document.readyState=='complete'){
??btnObj.disabled='';
??endRequestLoading();
?}else{
??setTimeout('RestEnableButton(\''+obj+'\')',1000);
?}
}

function RequestEndEnableBtn(obj){
??? var me = this;
??? this.foo = (typeof obj=="string")?document.getElementById(obj):obj;
??? this.foo.onblur = function(){
???????? var foo = me.foo;
???????? foo.disabled = 'disabled';
???????? startRequestLoading();
???????? setTimeout('RestEnableButton(\''+obj+'\')',1000);
??? }
}

?

new RequestEndEnableBtn('exportBtnId');

</script>

?

-------------------------------------改进-----------------------------------------

function RequestEnableButton(obj){?
?this.btnObj = (typeof obj=="string")?document.getElementById(obj):obj;
?if(window.document.readyState=='complete'){
??btnObj.disabled='';
??endRequestLoading();
?}else{
??setTimeout('RequestEnableButton(\''+obj+'\')',1000);
?}
}

function RequestEndEnableBtn(obj){
??? var me = this;
??? this.foo = (typeof obj=="string")?document.getElementById(obj):obj;
??? var orgFun = this.foo.onclick;
??? this.foo.onclick = function(){
?? ? ?var foo = me.foo;
??????? new orgFun();
??????? foo.disabled = 'disabled';
??????? startRequestLoading();
??????? setTimeout('RequestEnableButton(\''+obj+'\')',1000);
??? }
}

?

------------------------------------------? 改进? -----------------------------------------?

<input type="button" name="exportstaticsBtn" value="导出Excel" class="button" onmouseover="new EnableBtnOnCompleteObj(this);" onclick="searchViewPowerCardForBrushListForm.action='form.submit();"/>

?

//让按钮点击后不可用disabled,请求返回后自动可用; 在需用的按钮添加 onmouseover="new EnableBtnOnCompleteObj(this);"


function EnableBtnOnCompleteObj(obj){
?var me = this;
??? this.foo = (typeof obj=="string")?document.getElementById(obj):obj;
??? var orgFun = this.foo.onclick;???? ??//取得并保存原来的onclick函数到orgFun
??? if(obj.flag==undefined || obj.flag==false){
???? this.foo.onclick = function(){
??? ? ?var foo = me.foo;
???????? new orgFun();????????//加载原来的onclick函数
???????? foo.disabled = 'disabled';
???????? startRequestLoading();
???????? setTimeout(EnableBtnOnComplete,1000);
???? }
???? obj.flag = true;
??? }

?function EnableBtnOnComplete(){?
??this.foo = me.foo;
??if(window.document.readyState=='complete'){
???foo.disabled='';
???endRequestLoading();
??}else{
???setTimeout(EnableBtnOnComplete,1000);
??}
?}
}

?

--------------------------------- 改进 ----------------------------------------------

//让按钮点击后不可用disabled,请求返回后自动可用; 在需用的按钮添加 onmouseover="new EnableBtnOnCompleteObj(this);"
function EnableBtnOnCompleteObj(obj){
?var me = this;
??? this.foo = (typeof obj=="string")?document.getElementById(obj):obj;
??? var orgFun = this.foo.onclick;
??? if(obj.flag==undefined || obj.flag==false){
???? this.foo.onclick = function(){
??? ? ?var foo = me.foo;
???????? new orgFun();
???????? foo.disabled = 'disabled';
???????? startRequestLoading();
???????? setTimeout(EnableBtnOnComplete,1000);
???? }
???? obj.flag = true;
??? }

?function EnableBtnOnComplete(){?
??this.foo = me.foo;
??if(window.document.readyState=='complete'){
???foo.disabled='';
???endRequestLoading();
??}else{
???setTimeout(EnableBtnOnComplete,1000);
??}
?}
}

?

//添加了这些代码,在需要用到的按钮上只要添加一个属性 enableOnComplete="true" 即可

window.document.onmousedown=function(e){
?e = e||event;
?var el = e.srcElement || e.target;
?if(el.flag!=null) return;
?var eTag = el.tagName;
??? var eType = el.getAttribute('type') || '';
??? if((el.tagName=='INPUT' && eType.toUpperCase()=='BUTTON') || eTag=='BUTTON'){
??? ?if(el.getAttribute('enableOnComplete')!='' && el.getAttribute('enableOnComplete')=='true'){
??? ??new EnableBtnOnCompleteObj(el);
??? ?}
??? }
}

  相关解决方案