JS 获取Radio、CheckBox选中的值与文本

1、获取Radio选中的值与文本

	<input type="radio" name="advancedBespeak"  value="1"><input type="radio" name="advancedBespeak" checked="checked" value="0">var advancedBespeakRadio=document.getElementsByName("advancedBespeak");
for(var i=0;i<advancedBespeakRadio.length;i++){
	if(advancedBespeakRadio[i].checked==true) {
	    //选中的value
		alert(advancedBespeakRadio[i].value);
		//选中的text
		alert(advancedBespeakRadio[i].nextSibling.nodeValue);
	}
}

2、获取CheckBox选中的值与文本

	<input type="checkbox" id="product" name="product" value="1">Apple	
	<input type="checkbox" id="product" name="product" value="2">HUAWEI				

var products=document.getElementsByName("product");
for(var i=0;i<products.length;i++){
	var product=products[i];
	if(product.checked==true) {
		    //选中的value
			alert(product.value);
			//选中的text
			alert(product.nextSibling.nodeValue);
	}
}

版权声明:本文为tmaczt原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。