如何使用带有CI的jquery设置href模态

时间:2014-11-24 10:50:18

标签: javascript php jquery html continuous-integration

   <script>
        $(document).on("click", ".btn", function(){
            var dataID = $(this).data('id');
            var link = '<?php echo base_url()."admin/employees/deleteEmpOffice/";?>' + dataID;
            document.getElementById("deleteEmp").setAttribute("href",link);
        });
    </script>

这是我的jquery

                            <tbody>                                 
                                <?php  if (is_array($empOffice) && count($empOffice)) : foreach ($empOffice as $row ) : ?>
                            <tr>
                                <td> <?php  echo $row->employee_id;?></td>
                                <td> <?php  echo $row->employee_first_name; ?></td>
                                <td> <?php  echo $row->employee_last_name; ?></td>
                                <td> <?php  echo $row->employee_position; ?></td>
                                <td> <?php  echo $row->employee_address; ?></td>
                                <td> <?php  echo $row->employee_mobile; ?></td>
                                <td class="center">
                                <a class="btn btn-info" href="#">
                                    <i class="halflings-icon white edit"></i>  
                                </a>
                                <a class="btn btn-danger btn-setting"  href="<?php echo base_url(); ?>admin/vwDeleteModal" data-id="<?php echo  $row->employee_id;?>" >
                                    <i class="halflings-icon white trash"></i> 
                                </a>
                            </td>
                            </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                        </tbody>

这是带有view和delete选项的html部分,我在其中设置了data-id并链接到vwDeleteModal

<div class="modal hide fade" id="myModal">
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">×</button>
    <h3>Please Confirm</h3>
</div>
<div class="modal-body">
    <p>Are you sure?</p>
</div>
<div class="modal-footer">

    <a href="#" class="btn" data-dismiss="modal">Close</a>
    <a id="deleteEmp" class="btn btn-primary">OK</a>
</div>

使用<?php echo $this->load->view();?>

加载vwDeleteModal

现在当我点击vwDeleteModal中的Ok按钮时,url中的段(4)被认为是employee_id被声明为undefined而我无法删除该员工 请有人帮帮我吗?!!

2 个答案:

答案 0 :(得分:1)

要获取data-id的值,请尝试:

var dataID = $(this).attr('data-id');

而不是

var dataID = $(this).data('id');

编辑:

也许这解决了你的问题:

 <a class="btn btn-danger btn-setting"  href="<?php echo base_url(); ?>admin/vwDeleteModal/<?php echo  $row->employee_id;?>">
      <i class="halflings-icon white trash"></i> 
</a>

<a id="deleteEmp" class="btn btn-primary" data-id="<?php echo $this->uri->segment(3); ?>">OK</a>

答案 1 :(得分:0)

<script>
    $(document).on("click", ".btn", function(){
        var dataID = $(this).data('id');
        var href = $(this).attr('href');
        $('#deleteEmp').attr('href',href);
    });
</script>
<a class="btn btn-danger btn-setting"  href="<?php echo base_url()."admin/employees/deleteEmpOffice/"."$row->employee_id";?>" data-id="<?php echo  $row->employee_id;?>">
<i class="halflings-icon white trash"></i> 
</a>

我解决它们我只是从类中复制链接并将其设置为我的模态。谢谢你的时间