点击提交按钮后按钮变灰色不可用状态的三种方法
2013-09-17 09:53
519 查看
第一种方法:直接按钮中加入
当点击提交后,提交按钮变灰色不可用,这样可有效防止重复提交,本代码就是实现这样一个功能。从代码就可以看出,我们只需在提交按钮上加入这一句: onclick="javascript:{this.disabled=true;document.form1.submit();}",意思是当按钮点击后,将按钮的不可用属性设置为true,这样按钮就变灰了
第二种方法:通过onSubmit事件实现,并且可以将变灰按钮变为可用
在form里面添加 onSubmit事件,如果表单加入了判断,那么这个方法直接就可以用了,记住就放到最后,否则一开始就为灰了,但我们加上了一个使提交按钮变为可用的代码,
即可防止重复提交信息,也可以防止代码问题导致不可提交的情况
第三种,跟上面的类似
当点击提交后,提交按钮变灰色不可用,这样可有效防止重复提交,本代码就是实现这样一个功能。从代码就可以看出,我们只需在提交按钮上加入这一句: onclick="javascript:{this.disabled=true;document.form1.submit();}",意思是当按钮点击后,将按钮的不可用属性设置为true,这样按钮就变灰了
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>表单提交后按钮变成灰色</title> </head> <body> <form name=form1 method="POST" action="/" target=_blank> <p><input type="text" name="T1" size="20"><input type="button" value="提交" onclick="javascript:{this.disabled=true;document.form1.submit();}"> <input type="reset" value="重置" name="B2"></p> </form> </body> </html>
第二种方法:通过onSubmit事件实现,并且可以将变灰按钮变为可用
在form里面添加 onSubmit事件,如果表单加入了判断,那么这个方法直接就可以用了,记住就放到最后,否则一开始就为灰了,但我们加上了一个使提交按钮变为可用的代码,
即可防止重复提交信息,也可以防止代码问题导致不可提交的情况
<form name=form1 action="" onSubmit=" return closebut()" > <input name="imageField" type="submit" class="inputbut" value="确定" /><br> <input type="button" name="hui" id="hui" value="让提交按钮可用" onclick="document.form1.imageField.disabled=false" /> </form> <script> function closebut(){ document.form1.imageField.disabled=true; } </script>
第三种,跟上面的类似
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=gb2312"> <meta name="keywords" content="站长,网页特效,js特效,js脚本,脚本,广告代码" /> <meta name="description" content="," /> <title>网页特效 表单提交后按钮变灰效果三</title> </head> <body> <a href="http://www.dehome.net/">设计</a>,站长必备的高质量网页特效和广告代码。<hr> <!--欢迎来到脚本之家,我们网站收集大量高质量js特效,提供许多广告代码下载,网址:<A href="http://www.dehome.net">www.dehome.net</A>,用.net打造靓站--> <script language="javascript"> function submitonce(jb51_net){ if(document.all||document.getElementById){ for(i=0;i<jb51_net.length;i++){ var tempobj=jb51_net.elements[i]; if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") tempobj.disabled=true; } } }// </script> <form action="http://www.jb51.net" method="post" name="jb51_net" onSubmit="submitonce(this)"> <input type="text" name="name"> <input type="submit" name="submit1" value="提交"> </form> </body> </html>
相关文章推荐
- 提交按钮变灰色不可用状态
- JS实现点击复选框将按钮或文本框变为灰色不可用的方法
- JS实现点击复选框将按钮或文本框变为灰色不可用的方法
- 点击提交按钮后,让button变为不可用防止多次提交
- 关于表单提交按钮多次点击多次触发的解决方法
- 点击不同的按钮把同一个表单提交到不同的页面处理的方法
- 提交按钮在页面加载5秒后变为可用状态。
- js和jquery使按钮失效为不可用状态的方法
- asp.net 点击按钮提交后使按钮变灰不可用
- VC实现让关闭按钮成灰色不可用的方法
- android studio 添加按钮点击事件的三种方法
- 点击提交按钮后,让Button变为不可用防止多次提交
- 移动端点击某个按钮触发的时候,出现点击状态的方法
- 关于WinForm框架中点击按钮时存在的多次提交问题的解决方法
- 实现按钮点击倒计时的三种方法
- 表单提交时要点击两次按钮(Validform验证)才能成功的解决方法
- jquery下的提交,点击按钮没反应,post方法不执行 JSON方式在FORM表单下不起作用
- 【学习总结】三种发送短信的方法和四种按钮的点击事件