这会得到你的属性值
$('#row').attr('recordID');
如果你想获得当复选框被选中的值,这里有一个例子
JS文件
$(document).ready(function(){
$('input:checkbox').change(function(){
if($(this).attr('checked')){
alert($(this).parent().attr('recordID'));
}
});
});
要看看有多少行已检查:
JavaScript
$(document).ready(function(){
$('#check').click(function(event){
event.preventDefault();
alert($('input:checkbox:checked').size());
});
});
HTML
<span id="row1" recordID="1">
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
</span>
<span id="row2" recordID="2">
<input type="checkbox" style="left:10;" />
</span>
<span id="row3" recordID="3">
<input type="checkbox" style="left:10;" />
</span>
<span id="row4" recordID="4">
<input type="checkbox" style="left:10;" />
</span>
<button id='check'>Check Num Rows</button>
要检查单个的跨度
$(document).ready(function(){
$('#check').click(function(event){
event.preventDefault();
alert($('#row1 input:checkbox:checked').size());
});
});
这里内是我使用,使例子完整的示例代码,您需要
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type='text/javascript'>
$(document).ready(function(){
$('input:checkbox').change(function(){
alert($(this).parent().find(':checkbox:checked').size());
});
});
</script>
</head>
<body>
<span id="row1" recordID="1">
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
</span><br/><br/>
<span id="row2" recordID="2">
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
</span><br/><br/>
<span id="row3" recordID="3">
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
</span><br/><br/>
<span id="row4" recordID="4">
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
<input type="checkbox" style="left:10;" />
</span>
</body>
</html>
我该检查点击了多少行。 谢谢 – Autolycus 2010-06-25 18:36:12
我可以检查使用 alert($(“input [type = checkbox]:checked”)检查了多少个复选框。 但我希望能够只检查Span id =行。我该怎么做谢谢 – Autolycus 2010-06-25 18:40:46
wowo_999谢谢你的帮助。但由于某种原因,它不能给我在一个范围内检查的盒子总数 谢谢 – Autolycus 2010-06-25 18:50:54