使用jQuery无法在下一页上使用“编辑”按钮无法编辑我的数据

时间:2018-09-12 18:25:37

标签: php jquery

我想在下一页上编辑数据,但是我的编辑按钮在下一页上不起作用

我的用于编辑按钮的jquery是:

$('.edit_athlete').on('click', function (e) {
    e.preventDefault();
    $('.' + $(this).data("form"))[0].reset();
    $('.reset_a_form').hide();
    var formData = $(this).data("json");
    console.log(formData);
    formData = JSON.parse(JSON.stringify(formData));
    console.log(formData);
    var resp = $.fn.getState(formData.country);
    var resp = $.fn.getCity(formData.state);
    console.log(formData.country);
    $.each(formData, function (index, element) {
        if (index == 'user_image') {
            $('#' + index).removeAttr("required");
        } else if(index == 'gender'){
            if(element == 'Male'){
                $('#genderM').attr("checked",true);
                $('#genderF').attr("checked",false);
            }else{
                $('#genderF').attr("checked",true);
                $('#genderM').attr("checked",false);
            }
        } else if(index == 'user_name'){
            $('#user_name').val(element);
        } else if(index == 'password'){
            $('#password').val(element);
        }else if(index == 'dob'){
            $('#single_cal5').val(element);
        }else if (index != 'password'){
            $('#' + index).val(element);
        }


    });
    $('#password').removeAttr("required");
    $('#confirm_password').removeAttr("required");
    $('#function').val("update");
    $('.form_title').html('Edit Athlete');
    $('.password_block').hide();
    $('.Remove_password').hide();
    $('.update_password').show();
    $('.' + $(this).data("block")).show();
    $("html, body").animate({scrollTop: 0}, "slow");
});

我在编辑按钮上的查看代码:

<?php foreach ($data['athletes'] as $key => $value) { ?>
    <td><a href="#/pencil-square-o" class="edit_athlete option_icon" data-json='<?php echo json_encode($value, TRUE); ?>' data-block="athlete_form_block" data-form="athlete_form" ><i class="fa fa-edit"></i></a></td>
<?php  } ?>

我要在使用选择查询的网页上编辑页面

public function fetch_athlete($where = '') {
        $this->db->select('user.*, countries.name as countryName,, cities.name as cityName, states.name as stateName');
        $this->db->from('user');
        $this->db->group_by('user_id');
       // $this->db->join('user', 'user.parent_id = athlete.athlete_id', 'LEFT');
        $this->db->join('cities', 'cities.id = user.city', 'LEFT');
        $this->db->join('countries', 'countries.id = user.country', 'LEFT');
        $this->db->join('states', 'states.id = user.state', 'LEFT');
        $this->db->where('user_type',4);
        $query = $this->db->get();
        $result = $query->result_array();
        return $result;
    }

1 个答案:

答案 0 :(得分:0)

Jquery中的更改 仅替换为$('。edit_athlete')。on('click',函数(e){ 在jquery $(document).on('click','.edit_athlete',function(e){...

$(document).on('click', '.edit_athlete', function (e) {
    e.preventDefault();

    $('.' + $(this).data("form"))[0].reset();
    $('.reset_a_form').hide();
    var formData = $(this).data("json");
    console.log(formData);
    formData = JSON.parse(JSON.stringify(formData));
    console.log(formData);


    var resp = $.fn.getState(formData.country);
    var resp = $.fn.getCity(formData.state);
    console.log(formData.country);
    $.each(formData, function (index, element) {
        if (index == 'user_image') {
            $('#' + index).removeAttr("required");
        } else if(index == 'gender'){
            if(element == 'Male'){
                $('#genderM').attr("checked",true);
                $('#genderF').attr("checked",false);
            }else{
                $('#genderF').attr("checked",true);
                $('#genderM').attr("checked",false);
            }
        } else if(index == 'user_name'){
            $('#user_name').val(element);
        } else if(index == 'password'){
            $('#password').val(element);
        }else if(index == 'dob'){
            $('#single_cal5').val(element);
        }else if (index != 'password'){
            $('#' + index).val(element);
        }


    });
    $('#password').removeAttr("required");
    $('#confirm_password').removeAttr("required");
    $('#function').val("update");
    $('.form_title').html('Edit Athlete');
    $('.password_block').hide();
    $('.Remove_password').hide();
    $('.update_password').show();
    $('.' + $(this).data("block")).show();
    $("html, body").animate({scrollTop: 0}, "slow");
});