想做一个不符合条件提交按钮时灰色的按不了 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> JS正则批量替换,来正则高手 关于网站流量统计JS,应该放在什么位置比较适合,head,body,底部??? 网页用mideaplay播放时一执行javascript就播止 firefox 下ajax小问题 关于checkbox的问题 求教一个简单地JQ问题,如何获取某元素下没有class属性的子元素? 请问怎样实现在类似优酷打开视频页面的效果 只打开一个新窗口 再打开其他的视频页面 也只在第一次打开的新窗口更新链接地址 如何实现从SQL中读取数据,并实现多级关联 帮我找找错误 如何让这个函数允许负值? 想做一个不符合条件提交按钮时灰色的 按不了 有朋友帮忙看下 怎么修改这JS
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>