想做一个不符合条件提交按钮时灰色的按不了

fumaya 2014-10-28 11:34:24
想做一个格式不符合条件按钮就成灰色不能按 如果格式符合条件就能提交的文件 这个怎么实现啊 详细点 最好有代码 能告诉插入哪里么 谢谢了!
<body>
</form>
<form method="post" action=""id="allow">
<div id="form">
<div class="int">
<label for="username">用户名:</label>
<input type="text" id="username" class="input" reg="^[a-zA-Z0-9]{2,8}$" tip="用户名是1-8位不得使用_+!@#$d"/>
</div>

<div class="int">
<label for="txtpwd">密 码:</label>
<input type="password" id="txtpwd" class="input" reg="^[a-zA-Z0-9]{6,16}$" tip="密码由英文字母和数字字符组成!"/>
</div>
<br>
<input type="submit" value="提交" id="send" />
</form>
</body>
</html>
...全文
244 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
slwsss 2014-10-28
  • 打赏
  • 举报
回复
<form method="post" action=""id="allow">
<div id="form">
    <div class="int">
        <label for="username">用户名:</label>
        <input type="text" id="username" class="input"  reg="^[a-zA-Z0-9]{2,8}$"  tip="用户名是1-8位不得使用_+!@#$d"/>
    </div>
     
    <div class="int">
        <label for="txtpwd">密 码:</label>
        <input type="password" id="txtpwd" class="input"  reg="^[a-zA-Z0-9]{6,16}$" tip="密码由英文字母和数字字符组成!"/>
    </div>
<br>
<input type="submit" value="提交" id="send" />
</form>
<script>
var t=document.getElementById('send');
t.disabled=true;
var u=document.getElementById('username');
var p=document.getElementById('txtpwd');
function f(){
if(!u.value)return t.disabled=true;
if(!new RegExp(u.getAttribute('reg')).test(u.value)){ t.disabled=true;return alert(u.getAttribute('tip'));}
if(!p.value)return t.disabled=true;
if(!new RegExp(p.getAttribute('reg')).test(p.value)) {t.disabled=true;return alert(p.getAttribute('tip'));}
t.disabled=false;
}
u.onblur=f;p.onblur=f;
</script>
Go 旅城通票 2014-10-28
  • 打赏
  • 举报
回复
阻止表单提交就行了,干嘛要禁用提交按钮
<script>
    function check(f) {
        if (!new RegExp(f.username.getAttribute('reg')).test(f.username.value)) { alert(f.username.getAttribute('tip')); f.username.focus(); return false }
        if (!new RegExp(f.txtpwd.getAttribute('reg')).test(f.txtpwd.value)) { alert(f.txtpwd.getAttribute('tip')); f.txtpwd.focus(); return false }
    }
</script>
<form method="post" action="" id="allow" onsubmit="return check(this)">
<div id="form">
    <div class="int">
        <label for="username">用户名:</label>
        <input type="text" id="username" name="username" class="input"  reg="^[a-zA-Z0-9]{2,8}$"  tip="用户名是1-8位不得使用_+!@#$d"/>
    </div>
     
    <div class="int">
        <label for="txtpwd">密 码:</label>
        <input type="password" id="txtpwd" name="txtpwd" class="input"  reg="^[a-zA-Z0-9]{6,16}$" tip="密码由英文字母和数字字符组成!"/>
    </div>
<br>
<input type="submit" value="提交" id="send" />
</form>

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧