我正在处理复选框,当用户点击复选框我正在检查它是否已选中,如果选中我更新数据库,这里是我的代码
$(document).ready(function(){
$('input[type="checkbox"]').bind('click',function()
{
var tObj = $(this).val();
if ($('#checkpermission').is(':checked'))
{
alert(tObj);
$.ajax({
url: 'checkpermission.php',
data: {"Selected":tObj},
type: 'post',
success:function(data)
{
alert(data);
//Succes!
}
});
}
else
{
// alert(tObj);
$.ajax({
url: 'uncheckpermission.php',
data: {"Selected":tObj},
type: 'post',
success:function(data)
{
alert(data);
//Succes!
}
});
}
});
});
<?php
session_start();
require 'dbconnect.php';
$page_name="RegisterUsers.php";
$start=$_GET['start'];
if(strlen($start) > 0 and !is_numeric($start))
{
echo "Data Error";
exit;
}
$eu = ($start - 0);
$limit = 8;
$this1 = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
$query="select * from tbl_user where username!='admin' and password!='admin'";
$result=mysql_query($query);
$nume=mysql_num_rows($result);
if($nume>0)
{
if($_REQUEST['SearchText'])
{
$find=$_REQUEST['SearchText'];
$query="select * from tbl_user where username!='admin' and password!='admin' and username LIKE'%$find%' or Email LIKE'%$find%' or PhoneNumber LIKE'%$find%' order by id limit $eu, $limit";
}
else
{
$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_row($result))
{
if($data[5])
{
$path=$redirect."/services/User/".$data[5];
}
else
{
$path=$redirect."/images/noimage.png";
}
?>
<tr>
<td class="gallery">
<a href='<?=$path ?>'>
<img width="50" height="50" src=<?php echo $path; ?> />
</a>
</td>
<!--<td id='myText'><img width=50 height=50 src=<?php echo $path; ?> /></a></td>-->
<td><?=$data[1]?></td>
<td><?=$data[3]?></td>
<td><?=$data[4]?></td>
<td>
<div style="padding-left:25px;">
<INPUT TYPE="checkbox" class="checkpermission" name="checkuser" id="checkpermission" value='<?=$data[0]?>'<?php if($data[6]=="Read-Write"){echo "checked";}?>>
</div>
<div>
Read-Write
</div>
</td>
<td class='delete'><a href='http://ifliptips.com/admin/VueGuides/AddUser.php?id=<?=$data[0]?>&action=edit' >Edit</a></td>
<td class='delete'><a href='http://ifliptips.com/admin/VueGuides/RegisterUsers.php?id=<?=$data[0]?>&action=delete' onClick="return deletepressed();">Delete</a></td>
</tr>
<?php
}
}
?>
每次用户点击继续如果条件只有其他循环不工作我看到响应
所以任何人都可以指导我如何克服这一点 谢谢你的进步。
答案 0 :(得分:1)
$('input:checkbox:checked').val()
应该有效:)
答案 1 :(得分:1)
尝试使用
if($("#checkpermission:checked").length > 0)
<强>解决方案强>
checkpermission
复选框不止一个。所以代码需要像这样修改
$('input[type="checkbox"]').bind('click',function()
{
var tObj = $(this).val();
if ($(this).is(':checked'))
{
//Rest of the code
Ajay将更改代码以生成复选框的唯一ID。上面的代码也适用于这种情况。
希望这适合你。
答案 2 :(得分:0)