想做一个不符合条件提交按钮时灰色的 按不了 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> 我的HTML的编码是utf-8,js文件编码是ansi, 那<script元素的charset 属性该是什么? location.href的写法!!!! 框架页显示问题 JavaScript 缺少对象的问题! JSON中文问题 请教一个字符串转换函数怎么写? 请教ie的一个诡异问题 帮忙看看可移动层里的文本框怎么获得焦点 mozilla支持的JavaScript对象 仿小米网站在做小圆点切换动画时出现的问题 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>