js实现input button从不可用变为可用
有时候明明是些很简单的东西,因为自己的一些大意,可能就在那圈子里一直兜兜转转,好久都绕不出来。
所以我也愿意把这些很简单的愚蠢写出来,与君共享~
首先大家知道<input>有一个名叫“button”的type,它的可见与否由“disabled”属性决定。
下面的代码,我的原意是一个输入框和三个按钮。在点击“编辑”按钮前,另外三个都属于“不可用”状态,点击以后方能恢复可用。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title> <script type="text/javascript"> function edit(){
document.getElementById("editCode").disabled = true;
document.getElementById("inviteCode").disabled = false;
document.getElementById("randomCode").disabled = false;
document.getElementById("submitCode").disabled = false;
} </script>
</head>
<body>
<h3>邀请码设置</h3>
<s:form>
<table cellspacing="">
<tr>
<th>当前邀请码:</th>
<td><input type="text" name="inviteCode" id="inviteCode" value="" class="input" size="" disabled/></td>
<td><input type="button" name="randomCode" id="randomCode" value="随机获取" disabled/></td>
</tr>
<tr align="right">
<td><input type="button" name="editCode" id="editCode" value="编辑" onclick="edit()"/></td>
<td><input type="submit" name="submitCode" id="submitCode" value="确定" disabled/></td>
</tr>
</table>
</s:form>
</body>
</html>
很简单,就是在edit()函数里将各个元素的disabled类型设置为可用或者不可用。
中间我遇到了个很大的问题导致我一直以为自己找的解决方法不可用,那就是我将元素命名为“edit”、“submit”等等,可能与本身一些内容发生了冲突。审查元素后报错:object is not a function.
改名后一切得到解决。
js实现input button从不可用变为可用的更多相关文章
- input ,button, textarea 1)使用disabled , 2) 显示值, 3) 表单提交. 4) jquery.form.js ajaxSubmit() 无刷新ajax提交表单.
1.使用disabled input , button textarea 可以 被 禁用, 禁用的效果 : 1) 上面的点击事件无法使用 --- button : 下面的 onclick ...
- JS改变input的value值不触发onchange事件解决方案 (转)
方法(一)(转载的网络资料) 需要了解的知识 首先,我们需要了解onchange和onpropertychange的不同: IE下,当一个HTML元素的属性改变的时候,都能通过 onprope ...
- selenium web driver 使用JS修改input属性
selenium获取input时候,发现type=”hidden” 的input无法修改value,经牛人指点,可以使用js修改 首先html源文件如下,设置为text .hidden.submit ...
- js auto hover button & html5 button autofocus
js auto hover button & html5 button autofocus input // html 5 <input name="myinput" ...
- PHP——0128练习相关2——js点击button按钮跳转到另一个新页面
js点击button按钮跳转到另一个新页面 投稿:whsnow 字体:[增加 减小] 类型:转载 时间:2014-10-10我要评论 点击按钮怎么跳转到另外一个页面呢?点击图片要跳转到新的页面时,怎么 ...
- <asp:TextBox><asp:LinkButton><input button>调用后台方法后刷新页面
<asp:TextBox><asp:LinkButton>服务器控件,执行后台方法,会回调加载js,相当于页面重新加载,刷新页面 <input button>不能直 ...
- 通过js动态创建button
通过js动态创建button 一.实例描述 通过JS的DOM对象,实现元素的动态创建. 二.效果 三.代码 <!DOCTYPE html> <html lang="zh-c ...
- JS限制input输入的为数字并且有小数的时候最多保留两位小数
JS限制input用户输入的为数字并且有小数的时候最多保留两位小数,代码如下: html部分: <input type="number" onkeypress="r ...
- JS 捕获 input 中 键盘按键
JS 捕获 input 中 键盘按键 的相应处理事件是很简单的,google搜索一下很容易找到处理方式,请看如下一种简单的处理方式: HTML代码: <div> <input typ ...
随机推荐
- 递归与DP
每一个递归问题都可以改成DP来做...只不过DP会浪费一些空间罢了..DP只是把之前的结果存起来以防再算一遍罢了.....
- UIImageView的UserInteractionEnabled什么时候为no
UIImageView作为背景,但直接把按钮或者UITextField放在上面无法相应事件 特殊子类的覆盖 userInteractionEnabled属性默认值为YES,但UIView的一些子类中对 ...
- button的action属性如果有参数,必须加“:”
比如: [bt addTarget:self action:@selector(shareButtonClickHandler:) …… 后面未写完 一开始我没加,就报错.
- python的历史与优劣
历史 Python的创始人是Guido van Rossum,在发明Python语言之前Guido曾参与过一门称作ABC的语言的设计,ABC是专门为非专业程序员设计的:Guido在Python语言的设 ...
- html 时间单位
<style>h1{font-size:16px;} .test{position:absolute;left:8px;width:200px;height:100px;margin:0 ...
- 给php代码添加规范的注释phpDocumentor
给php代码添加规范的注释更多参考 http://phpdoc.org/docs/latest/index.html在phpdocumentor中,注释分为文档性注释和非文档性注释.所谓文档性注释,是 ...
- Docker学习笔记 — Docker私有仓库搭建【转载】
标签: Docker 2015-03-10 21:08 24190人阅读 评论(0) 收藏 举报 分类: Docker(26) 目录(?)[+] 和Mavan的管理一样,Dockers不仅 ...
- listview前几个item怎么不停加载
在加载前几个item的时候,listview有个Adapter,里面的getView方法会被调用好几遍.原因可能有两种: 1.listview在布局文件里高度写成了wrap_content <? ...
- linuxmint卸载软件
删除你已经卸载掉的软件包的命令为 sudo apt-get autoclean 还有一类软件包,我们每个人都应该删除,那就是你已经卸载了,但是一些只有它依赖而别的软件包都不需要的软件包还留在你的系统里 ...
- think in uml 2.1
业务建模