表单按纽问题 现在有一个表单,有用户名,密码,邮箱,如果信息不写,提交按纽不可用,如果全写了才可用,这种的代码怎么写啊。高手指点一下。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <form name="myform" action="" method="post" onsubmit="return checkform(this);">用户名:<input type="text" name="username" />密码:<input type="password" name="pwd" />邮箱:<input type="text" name="email" /><input type="submit" name="submit" value="提交" /></form><script language="javascript">function checkform(obj){ if(obj.username.value==''){ alert("用户名不能为空"); obj.username.focus();return flase;}if(obj.pwd.value==''){alert("密码不能为空"); obj.pwd.focus(); return flase;}if(obj.email.value==''){alert("邮箱不能为空"); obj.email.focus(); return flase;}}</script>你要的是不是这个,希望对你有用 <script language="javascript">function checkform(){ var obj = document.all.myform ; if(obj.username.value!='' &&obj.pwd.value!='' &&obj.email.value!=''){ obj.submit.disabled = false ; } else { obj.submit.disabled = true ; }}</script><form name="myform" id="myform" action="" method="post" >用户名:<input type="text" onKeyUp="checkform()" name="username" />密码:<input type="password" onKeyUp="checkform()" name="pwd" />邮箱:<input type="text" onKeyUp="checkform()" name="email" /><input type="submit" disabled="true" name="submit" value="提交" /></form> ps:根据楼上的改的,个人喜好比较习惯用id获取元素。手动写,未测试。楼主想进步就自己测试修改下实现自己想要的效果。嘿嘿//根据ID获取元素function $(id){ if(id)return document.getElementById(id);}//检查是否输入值function checkform(){ if($('username').value!='' && $('pwd').value!='' && $('email').value!=''){ $('sub').disabled = false ; } else { $('sub').disabled = true ; }}</script><form name="myform" id="myform" action="" method="post" >用户名:<input type="text" onKeyUp="checkform()" id="username" />密码:<input type="password" onKeyUp="checkform()" id="pwd" />邮箱:<input type="text" onKeyUp="checkform()" id="email" /><input type="submit" disabled="true" id="sub" value="提交" /></form> 想问个关于PHP网页连接数据库的问题 Discuz如何用户登录与我我网站如何整合,紧急求救!!!!! phpcms中如何在首页直接调用图片栏目中的最新图片(急) 各位帮个忙:dedecms伪静态 急切求助~ 关于集成支付宝接口的。。 请高手把这个ASP.net翻译成PHP 处理过期会员,怎样写更有效率? 正则表达式 排除 Apache邮件发送配置 PHP模拟登陆的问题 linux+apache+php+mysql 支持的最大并发量是多少 请教关于$_POST值时有时无的问题
用户名:<input type="text" name="username" />
密码:<input type="password" name="pwd" />
邮箱:<input type="text" name="email" />
<input type="submit" name="submit" value="提交" />
</form><script language="javascript">
function checkform(obj){
if(obj.username.value==''){
alert("用户名不能为空");
obj.username.focus();
return flase;}
if(obj.pwd.value==''){
alert("密码不能为空");
obj.pwd.focus();
return flase;
}
if(obj.email.value==''){
alert("邮箱不能为空");
obj.email.focus();
return flase;
}}
</script>
你要的是不是这个,希望对你有用
<script language="javascript">
function checkform(){
var obj = document.all.myform ;
if(obj.username.value!='' &&obj.pwd.value!='' &&obj.email.value!=''){
obj.submit.disabled = false ;
} else {
obj.submit.disabled = true ;
}
}
</script><form name="myform" id="myform" action="" method="post" >
用户名:<input type="text" onKeyUp="checkform()" name="username" />
密码:<input type="password" onKeyUp="checkform()" name="pwd" />
邮箱:<input type="text" onKeyUp="checkform()" name="email" />
<input type="submit" disabled="true" name="submit" value="提交" />
</form>
//根据ID获取元素
function $(id){
if(id)return document.getElementById(id);
}
//检查是否输入值
function checkform(){ if($('username').value!='' && $('pwd').value!='' && $('email').value!=''){
$('sub').disabled = false ;
} else {
$('sub').disabled = true ;
}
}
</script><form name="myform" id="myform" action="" method="post" >
用户名:<input type="text" onKeyUp="checkform()" id="username" />
密码:<input type="password" onKeyUp="checkform()" id="pwd" />
邮箱:<input type="text" onKeyUp="checkform()" id="email" />
<input type="submit" disabled="true" id="sub" value="提交" />
</form>