如何取得复选框的值?
百度了多个例子,都不执行,不知道原因:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>checkbox的操作</title>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
function go() {
var str="ww";
$("input[name='checkbox']:checkbox").each(function(){
if($(this).attr("checked")){
str += $(this).val()+",";
alert(str); //根本不执行
}
})
}
</script>
<body>
<div>
<input type="text" id="content" value="111"/>
<input type="checkbox" name="checkbox" value="1"/>
<input type="checkbox" name="checkbox" value="2"/>
<input type="checkbox" name="checkbox" value="3"/>
<input type="checkbox" name="checkbox" value="4"/>
<input type="checkbox" name="checkbox" value="5"/>
<input type="button" value="看结果" onclick="go();"/>
</div>
</body>
</html>
------解决方案--------------------<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>checkbox的操作</title>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
function gos() {
var str="ww";
$("input[name='checkbox']:checked").each(function(){
str += $(this).val()+",";
alert(str); //根本不执行
&nb