zoukankan      html  css  js  c++  java
  • 按钮置灰

    第一种方法:直接按钮中加入

    当点击提交后,提交按钮变灰色不可用,这样可有效防止重复提交,本代码就是实现这样一个功能。从代码就可以看出,我们只需在提交按钮上加入这一句: 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="www.jb51.net,站长特效网,站长必备js特效及广告代码。大量高质量js特效,提供高质量广告代码下载,尽在站长特效网" />
    <title>网页特效 表单提交后按钮变灰效果三</title>
    </head>
    <body>
    <a href="http://www.jb51.net/">脚本之家</a>,站长必备的高质量网页特效和广告代码。<hr>
    <!--欢迎来到脚本之家,我们网站收集大量高质量js特效,提供许多广告代码下载,网址:<A href="http://www.jb51.net">www.jb51.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;
    }
    }
    }//欢迎来到站长特效网,我们的网址是www.jb51.net,很好记,zz站长,js就是js特效,本站收集大量高质量js代码,还有许多广告代码下载。
    </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>

  • 相关阅读:
    miaomiao
    你猜中了
    にあたり等
    厉害的走
    JavaWeb学习 第6章 Servlet和Cookie
    JavaWeb学习 第3章 servlet编程
    BinaryStar代码分析前言
    框架学习之Struts2 第九节 Struts2重要的标签解说
    框架学习之Struts2 第八节 OGNL表达式
    JavaWeb学习 第1章 Web开发工具配置和使用(下)Tomcat的配置
  • 原文地址:https://www.cnblogs.com/ConfidentLiu/p/7299214.html
Copyright © 2011-2022 走看看