想做一个不符合条件提交按钮时灰色的 按不了 javascripthtml 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <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> <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> 老话题,li排列的的问题 亲们,关于window.onload,怎样让它与其他元素同步执行? JAVASCRIPT 字符问题 我想定义一个css,要求所有边框线,统统的没有,我自己写的无效,请指教 关于js全局变量的问题 求一去掉某字符串首尾空格的函数 为什么有的机器上禁止不了alt和ctrl键?? 在javascript中怎么动态改变字的颜色? 紧急!关于div的问题,如何把菜单拉到右边,即从左到右边拉出,而不是从上到下 unbind和bind解决叠加事件的原理 ie中如何定位光标的问题 想做一个不符合条件提交按钮时灰色的按不了
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>
<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>