怎么取<checkbox>标签选中的value值或title值?
<form name="f1">
a:<input type="checkbox" name="n1" value="a" title="1"><br/>
b:<input type="checkbox" name="n1" value="b" title="1"><br/>
c:<input type="checkbox" name="n1" value="c" title="1"><br/>
<input type="button" id="b" value="tijiao">
</form>
写到这里我就不会了,哪位大神帮帮忙,直接alert出来就行。
<script type="text/javascript">
var b = document.getElementById("b");
b.onclick = function(){
xxxxxxxx
xxxxxxxxxxx
}
</script> CheckBox value html
[解决办法]
<form name="f1">
a:<input type="checkbox" name="n1" value="a" title="1"><br/>
b:<input type="checkbox" name="n1" value="b" title="1"><br/>
c:<input type="checkbox" name="n1" value="c" title="1"><br/>
<input type="button" id="b" value="tijiao">
</form>
<script type="text/javascript">
var b = document.getElementById("b");
b.onclick = function(){
var chV="";
var inputElements =document.getElementsByTagName("input");
for(var i=0; inputElements[i]; ++i){
if(inputElements[i].name==="n1" && inputElements[i].checked){
chV+=inputElements[i].value+",";
}
}
alert(chV.substring(0,chV.length-1));
};
</script>