Home > Web Front-end > HTML Tutorial > 怎么取<checkbox>标签选中的value值或title值?_html/css_WEB-ITnose

怎么取<checkbox>标签选中的value值或title值?_html/css_WEB-ITnose

WBOY
Release: 2016-06-21 09:44:58
Original
1859 people have browsed it

CheckBox value html


a:

b:

c:






写到这里我就不会了,哪位大神帮帮忙,直接alert出来就行。
<script> <br /> var b = document.getElementById("b"); <br /> b.onclick = function(){ <br /> xxxxxxxx <br /> xxxxxxxxxxx <br /> } <br /> </script>

回复讨论(解决方案)

<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>
Copy after login

<script> <br /> var b = document.getElementById("b"); <br /> b.onclick = function(){ <br /> var sign = 0; <br /> var inputs = document.getElementsByTagName('input');//获取所有的input标签对象。 <br /> for(var i=0;i<inputs.length;i++){ <br /> var obj = inputs[i]; <br /> if(obj.type=='checkbox'){ <br /> if(obj.checked==true){ <br /> sign=1; <br /> alert(obj.value); <br /> } <br /> } <br /> } <br /> if(sign==0)//没有被选择项 <br /> { <br /> alert("未选择"); <br /> } <br /> } <br /> <br /> </script>

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template