如何使链接编辑codeigniter

时间:2017-05-17 03:46:54

标签: javascript php codeigniter

我在codeigniter中有一些脚本,但我在这里混淆了make链接编辑和删除,因为有一个变量。请告诉我......

	$edit 	= '<a data-uk-tooltip title="Edit" class="md-btn md-btn-warning md-btn-mini md-btn-wave-light waves-effect waves-button waves-light" href="javascript:void(0)"><i class="uk-icon-pencil uk-icon-small"></i></a>';
			$delete = '<a data-uk-tooltip title="Delete" class="md-btn md-btn-danger md-btn-mini md-btn-wave-light waves-effect waves-button waves-light" href="javascript:void(0)"><i class="uk-icon-trash uk-icon-small"></i></a>';

2 个答案:

答案 0 :(得分:1)

我理解了这个结论

<?php
echo $edit  = '<a data-uk-tooltip title="Edit" class="md-btn md-btn-warning md-btn-mini md-btn-wave-light waves-effect waves-button waves-light" href="javascript:void(0)" id="1" onclick="deleteData(this.id)"><i class="uk-icon-pencil uk-icon-small"></i>Edit</a>';
echo $delete = '<a data-uk-tooltip title="Delete" class="md-btn md-btn-danger md-btn-mini md-btn-wave-light waves-effect waves-button waves-light" href="javascript:void(0)" id="1" onclick="editData(this.id)"><i class="uk-icon-trash uk-icon-small"></i>Delete</a>';

 ?>

<script type="text/javascript">
    function deleteData(id) {
        alert(id);
        //delete data with ajax call
    }
    function editData(id) {
        alert(id);
        //edit data with ajax call
    }
</script>

&#13;
&#13;
    function deleteData(id) {
        alert(id);
        //delete data with ajax call
    }
    function editData(id) {
        alert(id);
        //edit data with ajax call
    }
&#13;
<a data-uk-tooltip title="Edit" class="md-btn md-btn-warning md-btn-mini md-btn-wave-light waves-effect waves-button waves-light" href="javascript:void(0)" id="1" onclick="deleteData(this.id)"><i class="uk-icon-pencil uk-icon-small"></i>Edit</a>
<a data-uk-tooltip title="Delete" class="md-btn md-btn-danger md-btn-mini md-btn-wave-light waves-effect waves-button waves-light" href="javascript:void(0)" id="1" onclick="editData(this.id)"><i class="uk-icon-trash uk-icon-small"></i>Delete</a>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

<?php
  echo $edit  = '<a data-uk-tooltip title="Edit" class="md-btn md-btn-warning md-btn-mini md-btn-wave-light waves-effect waves-button waves-light" href="javascript:void(0)" data-id="1" data-action="Edit" onclick="btnAction($(this).data('id'),$(this).data('action'))"><i class="uk-icon-pencil uk-icon-small"></i>Edit</a>';
  echo $delete = '<a data-uk-tooltip title="Delete" class="md-btn md-btn-danger md-btn-mini md-btn-wave-light waves-effect waves-button waves-light" href="javascript:void(0)"  data-id="1" data-action="Delete" onclick="btnAction($(this).data('id'),$(this).data('action'))"><i class="uk-icon-trash uk-icon-small"></i>Delete</a>';
?>
<script type="text/javascript">
  function btnAction(id,action){
    var request = $.ajax({
                url: '<?php echo site_url('your-controller/method'); ?>',
                method: "POST",
                data: {
                  id:id,
                  action:action
                },
                cache: false,
                contentType: false,
                processData: false,
                dataType: "json"
            });
    request.done(function( status ) {
                console.log(status);
            )};
  }
</script>