1、checkbox
例如
html:
<div>
<label>
<input type="checkbox" value="刁民" name = "test">刁民
<input type="checkbox" value="良民" name = "test">良民
<input type="checkbox" value="土匪" name = "test">土匪
</label>
</div>
获取值:
var species = document.getElementsByName("test");
var tests = new Array();
for(var i = 0; i<test.length;i++){
if(species[i].checked){
tests.push(test[i].value);
}
}
console.log(tests); // 是多选的值
2、radio**
例如:
html:
<div >
<label>
<input type="radio" value="刁民" name="test"> 刁民
<input type="radio" value="良民" name="test"> 良民
<input type="radio" value="良民" name="test"> 土匪
</label>
</div>
获取值:
var result= $('input[name="test"]:checked').val();
console.log(result); //单选的值