Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 复选框SaveonChange函数_Php_Jquery_Mysql_Codeigniter_Onchange - Fatal编程技术网

Php 复选框SaveonChange函数

Php 复选框SaveonChange函数,php,jquery,mysql,codeigniter,onchange,Php,Jquery,Mysql,Codeigniter,Onchange,我正在尝试创建一个脚本来保存勾选的复选框。我现在拥有的代码在勾选“读取”时禁用“添加和批准”,在勾选“添加/批准”时禁用“读取”。现在的问题是,当我将ajax提交添加到jquery时,它不会保存记录,也不会再禁用复选框(假设我勾选了read) 这是我到目前为止得到的 $(document).ready(function(){ $('#list-tbl tr').each(function(){ var $this = $(this); var id =

我正在尝试创建一个脚本来保存勾选的复选框。我现在拥有的代码在勾选“读取”时禁用“添加和批准”,在勾选“添加/批准”时禁用“读取”。现在的问题是,当我将ajax提交添加到jquery时,它不会保存记录,也不会再禁用复选框(假设我勾选了read)

这是我到目前为止得到的

$(document).ready(function(){
    $('#list-tbl tr').each(function(){

        var $this = $(this);
        var id = $('#input').val();
        $('input[type=checkbox]', $this).change(function(){
            if($('.read', $this).is(':checked')){
                $('input[type=checkbox]', $this).prop('disabled',true);
                $.ajax({
                    type: 'POST',
                    url: <?= site_url('admin/update')?>,
                    dataType: "json",
                    data: { id: id }, 
                    success: function(data) { 
                        alert("Updated");
            }
        });
                $(this).prop('disabled',false);
            } else if($('.add', $this).is(':checked') || $('.approve', $this).is(':checked')) {
                $('.read', $this).prop('disabled', true);
                $(this).prop('disabled', false);
            } else{
                $('input[type=checkbox]', $this).prop('disabled',false);
                $(this).prop('disabled',false);
            }
        });
    });
});
$(文档).ready(函数(){
$('#list tbl tr')。每个(函数(){
var$this=$(this);
var id=$('#input').val();
$('input[type=checkbox],$this).change(function(){
如果($('.read',$this).is(':checked')){
$('input[type=checkbox],$this.prop('disabled',true);
$.ajax({
键入:“POST”,
网址:,
数据类型:“json”,
数据:{id:id},
成功:函数(数据){
警报(“更新”);
}
});
$(this.prop('disabled',false);
}else if($('.add',$this).is(':checked')|$('.approve',$this).is(':checked')){
$('.read',$this.prop('disabled',true);
$(this.prop('disabled',false);
}否则{
$('input[type=checkbox],$this.prop('disabled',false);
$(this.prop('disabled',false);
}
});
});
});
例:

我有点沮丧,我只想以正确的方式保存数据并按原样执行禁用


非常感谢。

看着你的JSFIDLE。。。实际上,您没有一个带有
id=“input”
的HTML元素,尽管您试图使用:
var id=$('#input').val()保存一个id

这是您试图发送到服务器的id,但它实际上不存在。你到底想干什么?确定某个用户是否已阅读/添加/批准特定项目?如果是这种情况,您需要向服务器发送的是一个用户id和一个字符串,该字符串表示用户是否读取/添加或批准了某个项目


在一个次要的注释中,作为冗余和性能的问题:
$(this).prop('disabled',false)
在所有条件中都很常见,并且可以作为一个公共因素放在前面。

从我们的角度来看,很难确定您的问题到底是什么。你会考虑使用附带的HTML吗?