js复选框checkbox取值

<script language=javascript>
function popup(id){
 document.getElementById("text"+id).value="";
 for(var i=0;i<document.getElementsByName("checkbox"+id).length;i++){
  if(document.getElementsByName("checkbox"+id)[i].checked){
   //alert(document.getElementsByName("checkbox1")[i].value);
   document.getElementById("text"+id).value=document.getElementById("text"+id).value+"<br/>"+document.getElementsByName("checkbox"+id)[i].value;
  }else{
  }
 }
 return false;
}
</script>
 <label>
                <input type="checkbox" name="checkbox1" id="checkbox1" value="乒乓" onclick="popup(1)" />
               乒乓
              </label>
              <label>
                <input type="checkbox" name="checkbox1" id="checkbox1" value="篮球" onclick="popup(1)" />
                篮球 </label>
              <label>
                <input type="checkbox" name="checkbox1" id="checkbox1" value="足球" onclick="popup(1)" />
                足球 </label>
              <label>
                <input type="checkbox" name="checkbox1" id="checkbox1" value="排球" onclick="popup(1)" />
                排球</label>
              <label>
                <input type="checkbox" name="checkbox1" id="checkbox1" value="其他" onclick="popup(1)" />
                其他
</label>
<input type="hidden" value="" name="text1" id="text1" />

    A+
发布日期:2009年09月24日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: