javascript - 单击时更改按钮颜色 - 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ı";
}
} ?>
解决方案
一个简单的解决方案是尝试removeClass
和addClass
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");
推荐阅读
- python - 将word文档放入数据框
- ms-access - 加载事件上的 MS Access 运行时错误 438
- mysql - 无法将 AWS lambda 连接到 mysql 数据库
- python - echarts/pyecharts:dataZoom从0开始
- c++ - 一种后增量运算符,允许在指定的步长上进行增量
- mysql - MySql:由于异常命令导致的存储过程语法错误
- javascript -
从制表符 xlsx 导出中的列标题中删除 - python - 为什么 `multiprocessing.Queue` 使用馈线线程?
- javascript - 具有多个状态值的 React 钩子不起作用但单独的状态值起作用
- spring - 在 Windows 中创建 gradle 项目期间无法安装 Gradle 发行版