我需要在 jQuery 中获取复选框值。 这是我的代码:
$(document).ready(function() {
$('input[type="checkbox"]').bind('click',function() {
var tObj = $('#checkpermission');
var tVal = tObj.val();
alert(tVal);
});
});
$query="select * from tbl_user where username!='admin' and password!='admin' order by username limit $eu, $limit";
$result=mysql_query($query);
while($data=mysql_fetch_array($result)) {
<td><INPUT TYPE="checkbox" name="checkuser" id="checkpermission" onclick="changePage()" value='<?=$data[0]?>'></td>
<?php
}
每次我只得到第一个值。做错了什么?
最佳答案
您可以执行以下操作:
$(document).ready(function(){
$('input[type="checkbox"]').bind('click',function()
{
alert($(this).is(":checked"));
//Or you could use alert($(this).attr("checked") == "checked");
});
});
更新:添加了检查以查看复选框是否已选中。
关于php - 在 jQuery 中获取复选框值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8816095/