js 控制按钮点击后不可用
<input type="button" id="btn" value="免费获取验证码" />
<script type="text/javascript">
var wait=60;
function time(o) {
if (wait == 0) {
o.removeAttribute("disabled");
o.value="免费获取验证码";
wait = 60;
} else {
o.setAttribute("disabled", true);
o.value="重新发送(" + wait + ")";
wait--;
setTimeout(function() {
time(o)
},
1000)
}
}
document.getElementById("btn").onclick=function(){time(this);alert('aaaaaa');}
</script>
收集有效用户,为了防止用户多次点击某按钮,造成多次提交表单的操作。某些按钮需要在点击后实现不可用操作。发送使用ajax实现

例子:
<html>
<head>
<title>同意条款</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<input type="submit" name="Submit" value="同意" />
</form>
<script language="javascript">
document.form1.Submit.disabled = true;
var wait = 9; //停留时间
function updateinfo(){
if(wait == 0){
document.form1.Submit.value = "我同意";
document.form1.Submit.disabled = false;
}
else{
document.form1.Submit.value = "阅读条款"+wait;
wait--;
window.setTimeout("updateinfo()",1000);
}
}
updateinfo();
</script>
</body>
</html>
设置按钮的不可用 用到了 disabled属性。
语法:
object.disabled = false | true;
例子:w3cschool
<html>
<head>
<script type="text/javascript">
function disable()
{
document.getElementById('txt1').disabled=true;
}
function enable()
{
document.getElementById('txt1').disabled=false;
}
</script>
</head>
<body>
<textarea id="txt1">
Hello world....This is a text area
</textarea>
<br />
<input type="button" onclick="disable()" value="Disable" />
<input type="button" onclick="enable()" value="Enable" />
</body>
</html>
来源:https://my.oschina.net/mickelfeng/blog/109038
js 控制按钮点击后不可用的更多相关文章
- 安装node.js后npm不可用
安装node.js后npm不可用 最近要用Vue做项目,依赖node.js,于是按官网下载安装node 下载地址:https://nodejs.org/en/download/ 网上也有很多教程这里就 ...
- [King.yue]Grid列选中JS控制按钮状态
Grid列选中一行某些按钮启用 例:gridId(Grid ID) btnEditId(编辑按钮ID) btnDeleteId(删除按钮ID) JS: var setButtonStatus = ...
- js设置按钮不可用
<input type="button" value="确定" id="stamp" onclick="stampBill( ...
- JS控制按钮不能连续被点击
将下面代码拷贝进一个html文件中就可以运行查看效果. function downLoad(evt) { disabledButton(); MyPeriodicalExecuter(evt); } ...
- js简单分页,可用
//翻页调用 var pageSize = 1; var counts = 1; var current_page = 1; var rows,total; search(); //查询所有 func ...
- js 倒计时 button不可用
function showtime() { fun_timedown(5); } function fun_timedown(time) { $("#timedown").val( ...
- vue.js实现点击后动态添加class及删除同级class
最近使用vue需要实现一个点餐选择商品规格的页面,需要通过vue动态的给被点击的元素添加class名字,使其变色,其他的删除class.如图: 开始在网上找了许多办法发现不是太好用,最后找到一个发现还 ...
- BootStrap中按钮点击后被禁用按钮的最佳实现方法
//禁用button $('button').addClass('disabled'); // Disables visually $('button').prop('disabled', true) ...
- JS将指定的时间戳转为UTC时间
Js中获取时间戳可用var dayMiliseconds = parseInt(new Date().valueOf());Js的时间戳单位为毫秒(1s = 1000 ms),下面是一个将制定的格式转 ...
随机推荐
- 标准C++ I/O库 迭代器让数据自由流动 V8
IO库的组成 三种流 C++的IO库以流对象为实体.主要有三种流: (1)标准输入输出流 (2)文件输入输出流 (3)字符串输入输出流 流迭代器 输入输出流迭代器 instream_iterator& ...
- atitit.提升开发效率---使用server控件生命周期 asp.net 11个阶段 java jsf 的6个阶段比較
atitit.提升开发效率---使用server控件生命周期 asp.net 11个阶段 java jsf 的6个阶段比較 例如以下列举了server控件生命周期所要经历的11个阶段. (1)初始 ...
- 在页面左右一个悬浮div兼容IE6 IE7 8 9 Firefox chrome
在页面左右一个悬浮div兼容IE6 IE7 8 9 Firefox chrome #identifier-pannel { bottom: 345px; margin-left: 512px; pos ...
- 怎样删除Weblogic Domain?
转自:http://blog.csdn.net/biplusplus/article/details/7433558 旁白 由于没有现成的配置工具可以做这件事,我们需要手工来删除. 正题 以下方法适用 ...
- Oracle一些查询的习题,初学者一定要练习,蛮不错的
1. select * from emp; 2. select empno, ename, job from emp; 3. select empno 编号, ename 姓名, job 工作 fro ...
- XP如何找到网上邻居
右击桌面,点击属性,切换到桌面,自定义桌面,勾选网上邻居即可.
- CAD启动找不到AC1ST16.DLL
今天在安装Win7 x64上CAD2006启动报错:找不到ac1st16.dll文件. 一查,是系统变量的问题.在系统变量Path中cad的路径为: C:\Program Files (x86)\Co ...
- 在xcode5下利用Source Control 做 git 项目管理
xcode5做了很大的更新,其中一点非常实用的功能是集成了Source control项目管理,而且和git做了完美的结合:非常实用: 使用: 在新建项目时,选择 下面的 Create a git r ...
- 【转】C++ 虚函数&纯虚函数&抽象类&接口&虚基类
1. 动态多态 在面向对象语言中,接口的多种不同实现方式即为多态.多态是指,用父类的指针指向子类的实例(对象),然后通过父类的指针调用实际子类的成员函数. 多态性就是允许将子类类型的指针赋值给父类类型 ...
- STL源码剖析(list)
SGI STL中list是使用环状双向链表实现的.它的结点结构定义如下: template <class T> struct __list_node { typedef void* voi ...