首页 > 解决方案 > 单击时更改按钮颜色 - Bootstrap

问题描述

如果该过程成功,我想将“btn-success”类更改为“btn-warning”。或者我们可以将颜色代码更新为“#ffc107”。我怎样才能做到这一点?

按钮 ;

<button type="submit" name="teklifver" value="Teklif Ver" class="btn btn-block btn-success" id="teklifpasif">Teklif Ver</button>

php代码;

...

    $insert=$query->execute(array(

        "arac_id" =>$arac_id,
        "kullanici_adsoyad"=>$kullcek['kullanici_adsoyad'],
        "ihale_secenek" =>$ihale_secenek

        ));


        if($insert)
        {

          header("Location:index.php");
          ?>

          <script>

            // -------- Must be "btn-warning" ------------

          </script>

          <?php 
        }
        else 
        {
            echo "olmadı";
        }

}  ?>

标签: javascriptbootstrap-4

解决方案


一个简单的解决方案是尝试removeClassaddClass

https://api.jquery.com/removeClass/#removeClass-className

$('#teklifpasif').removeClass('btn-success').addClass('btn-warning');

或者你也可以试试toggleClass

https://api.jquery.com/toggleClass/#toggleClass-className

$('#teklifpasif').toggleClass('btn-success btn-warning');

更新

$(document).ready(function () {
   $('#teklifpasif').removeClass('btn-success').addClass('btn-warning');
 });

错误

header("Location:index.php");您之前添加的问题,script因此您的脚本在您删除之前不会执行header("Location:index.php");

消除header("Location:index.php");


推荐阅读