[英]Change button color when clicked - Bootstrap
If the process is successful, I want to change the "btn-success" class to "btn-warning".如果该过程成功,我想将“btn-success” class 更改为“btn-warning”。 Or we can update the color code to "# ffc107".或者我们可以将颜色代码更新为“#ffc107”。 How can I do that?我怎样才能做到这一点?
Button;按钮;
<button type="submit" name="teklifver" value="Teklif Ver" class="btn btn-block btn-success" id="teklifpasif">Teklif Ver</button>
Php Code; 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ı";
}
} ?>
a simple solution for this is trying removeClass
and addClass
一个简单的解决方案是尝试removeClass
和addClass
https://api.jquery.com/removeClass/#removeClass-className https://api.jquery.com/removeClass/#removeClass-className
$('#teklifpasif').removeClass('btn-success').addClass('btn-warning');
Or you can also try toggleClass
或者你也可以试试toggleClass
https://api.jquery.com/toggleClass/#toggleClass-className https://api.jquery.com/toggleClass/#toggleClass-className
$('#teklifpasif').toggleClass('btn-success btn-warning');
Update更新
$(document).ready(function () {
$('#teklifpasif').removeClass('btn-success').addClass('btn-warning');
});
ERROR错误
the problem in you have added header("Location:index.php");
您添加了header("Location:index.php");
中的问题before script
so your script won't execute until you remove header("Location:index.php");
在script
之前,因此您的脚本在您删除header("Location:index.php");
之前不会执行
remove header("Location:index.php");
删除header("Location:index.php");
Those are some options for you in JavaScript and JQuery.这些是 JavaScript 和 JQuery 中的一些选项。
$("#teklifpasif").css("background-color", "#ffc107");
$('#teklifpasif').removeClass('btn-success').addClass('btn-warning');
$('#teklifpasif').toggleClass('btn-success btn-warning');
document.getElementById("teklifpasif").style.color = "#ffc107";
document.getElementById("teklifpasif").classList.remove('btn-success');
document.getElementById("teklifpasif").classList.add('btn-warning');
They all work, I tried them a while ago.它们都有效,我不久前尝试过它们。
Just choose one of those options ^^只需选择其中一个选项^^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.