当单击活动按钮php jquery时如何更改颜色

时间:2018-07-30 11:31:56

标签: php jquery mysql ajax

我想在单击活动和非活动按钮时切换活动按钮

$('.factive').click(function(){

  var factiveId = $(this).attr('id');
  $.post('controller/ajax-product-active.php?factiveId='+factiveId,
  {},function(data)
    {  
      $('#product-active').html(data);
    });
  });

ajax-product-active.php

if ($csrow['status']=='Active') {

    $update_status = mysqli_query($conn,"update products set status = 'Deactive' where id = '{$factiveId}'");

    echo "<a id='$csrow[id]' class='factive' style='cursor: pointer;'  onclick='productActive($csrow[id])'>
                    <i class='fa fa-circle pactive' aria-hidden='true'style='color:red' title='Deactive'></i></a>";

}elseif ($csrow['status']=='Deactive') {

    $update_status = mysqli_query($conn,"update products set status = 'Active' where id = '{$factiveId}'");

    echo "<a id='$csrow[id]' class='factive' style='cursor: pointer;'  onclick='productActive($csrow[id])'>
                    <i class='fa fa-circle pactive' aria-hidden='true'style='color:#12bc00' title='Active'></i></a>";
}

此代码运行成功,但颜色仅在第一时间更改。

0 个答案:

没有答案