禁用<a> tag if condition true in codeigniter

时间:2018-09-10 05:50:41

标签: php codeigniter-3

My HTML code was

<li >
  <a href="<?php echo base_url('admin/uploadSales'); ?>" id="uploadsales">
  <i class="fa fa-dashboard fa-lg"></i> Upload Sales
  </a>
</li>

and my php code to disable anchor tag is

<?php
  $roleid=$this->session->userdata('roleid');
  if($roleid === '1') 
  {
    echo '<script> $("#uploadsales").prop("disabled", true); </script>';
    </script>';
  }
?>

I have to used same code to disable button in php without codeigniter it is worked

1 个答案:

答案 0 :(得分:1)

不需要<script></script>。转到三元运算符,检查条件,然后根据该条件删除整个链接本身。

<?php
   $roleid=$this->session->userdata('roleid');
?>
<li >
    <a href="<?php  echo ($roleid ==1) ? 'javascript:void(0)' : base_url('admin/uploadSales'); ?>" id="uploadsales">
    <i class="fa fa-dashboard fa-lg"></i> Upload Sales
    </a>
</li>