不要用JQUERY
用JS怎么写一个
我先前发的贴子没写明白,
从新发个贴。
提交框里的内容都被添写和被选中CHECKBOX中的一个?
谢谢。<script>
function check_value(){ } </script>
<form name="member_join_form" action="mem_join_04.php" method="post" enctype="multipart/form-data" onsubmit="return check_value();">
<input name="username" type="text" >
<input name="password" type="text" >
<input name="addr" type="text" >
<input name="tel" type="text" >
<label><input type="checkbox" name="cate[]" value="6">aa</label> <label><input type="checkbox" name="cate[]" value="7">bb</label> <label><input type="checkbox" name="cate[]" value="8">cc</label><br> <label><input type="checkbox" name="cate[]" value="2">dd</label><br> <label><input type="checkbox" name="cate[]" value="9">ee</label> </form>
用JS怎么写一个
我先前发的贴子没写明白,
从新发个贴。
提交框里的内容都被添写和被选中CHECKBOX中的一个?
谢谢。<script>
function check_value(){ } </script>
<form name="member_join_form" action="mem_join_04.php" method="post" enctype="multipart/form-data" onsubmit="return check_value();">
<input name="username" type="text" >
<input name="password" type="text" >
<input name="addr" type="text" >
<input name="tel" type="text" >
<label><input type="checkbox" name="cate[]" value="6">aa</label> <label><input type="checkbox" name="cate[]" value="7">bb</label> <label><input type="checkbox" name="cate[]" value="8">cc</label><br> <label><input type="checkbox" name="cate[]" value="2">dd</label><br> <label><input type="checkbox" name="cate[]" value="9">ee</label> </form>
function check_value(){
var _input = document.getElementsByTagName('input');
var checkedCount = 0;
for(var i in _input){
if(_input[i].type=='checkbox'&&_input[i].checked){
++checkedCount;
}
}
if(checkedCount>0){
return true;
}
return false;
}
return document.getElementById(id);
}
function check_value(){
var _input = document.getElementsByTagName('input');
if($('username').value==''){
return false;
}
if($('password').value==''){
return false;
}
if($('addr').value==''){
return false;
}
if($('tel').value==''){
return false;
}
var checkedCount = 0;
for(var i in _input){
if(_input[i].type=='checkbox'&&_input[i].checked){
++checkedCount;
}
}
if(checkedCount>0){
return true;
}
return false;
}
这个没添写时要提示:请输入用户名。
<input name="password" type="text" >
这个没添写时要提示:请输入密码。
<input name="addr" type="text" >
这个没添写时要提示:请输入地址.
需要一个一个提示的那种。
<script>
function $(id){
return document.getElementById(id);
}
function check_value(){
var _input = document.getElementsByTagName('input');
if($('username').value==''){
return false;
}
if($('password').value==''){
return false;
}
if($('addr').value==''){
return false;
}
if($('tel').value==''){
return false;
}
var checkedCount = 0;
for(var i in _input){
if(_input[i].type=='checkbox'&&_input[i].checked){
++checkedCount;
}
}
if(checkedCount>0){
return true;
}
return false;
}
</script>
<form name="member_join_form" action="mem_join_04.php" method="post" enctype="multipart/form-data" onsubmit="return check_value();">
<input name="username" id="username" type="text" >
<input name="password" id="password" type="text" >
<input name="addr" id="addr" type="text" >
<input name="tel" id="tel" type="text" >
<label><input type="checkbox" name="cate[]" value="6">aa</label>
<input type="submit">
</form>
function check_value(){
var f=document.member_join_form;
if(f.username.value == ''){
alert('请输入姓名.');
f.username.focus();
return false;
}
else if(f.password.value == ''){
alert(请输入密码.');
f.password1.focus();
return false;
}}我原来的代码是这样的,
这个的INPUT TEXT 很多,我已经写好了。
但是我不会CHECKBOX的判断,
我不想改INPUT TEXT 的判断JS
JS内容太多了。
function check_value(){
var _input = document.getElementsByTagName('input');
var checkedCount = 0;
for(var i in _input){
if(_input[i].type=='checkbox'&&_input[i].checked){
++checkedCount;
}else if(_input[i].type=='test'&&_input[i].value==''){
return false;
}
}
if(checkedCount>0){
return true;
}
return false;
}
_input[i].type=='test'
改成
_input[i].type=='text'