有个小问题,
目前我的 Test.php 文件中有 2 个选项框。当我在第一个选项中选择 leverancier 时,我想显示我的第二个选项框。到目前为止,一切都很好! 但现在我想给它应用一些 CSS ... 例如 Bootstrap 表单控制类...
这是我的(简单的)代码:
<script>
$(function() {
$("#corracrtieby").on("change", function() {
var select_val = $(this).val();
console.log(select_val);
if (select_val === 'Leverancier') {
$("#Klanttable").removeClass("hidden");
}
else {
$("#Klanttable").addClass("hidden");
$("#Klanttable").val("");
}
});
});
</script>
Correctie maatregelen:<br>
<select name="corracrtieby" class="form-control" id="corracrtieby" style="width: 300px">
<option value="--corracrtieby--">--corracrtieby--</option>
<option value="Petrogas">Petrogas</option>
<option value="Leverancier">Leverancier</option>
<option value="Klant">Klant</option>
</select>
<br>
<select name="Klanttable" class="hidden" id="Klanttable" style="width: 300px">
<option value="--Klanttable--">--Correctie maatregel--</option>
<option value="Test1">Petrogas</option>
<option value="Test2">Leverancier</option>
<option value="Test3">Klant</option>
<option value="Test4">Klant</option>
<option value="Test5">Klant</option>
</select>
那么我怎样才能让我的第一个选项框和我的第二个选项框一样呢?
最佳答案
使用 Jquery,您可以一次添加多个类,因此您的解决方案就是:
$(function() {
$("#corracrtieby").on("change", function() {
var select_val = $(this).val();
console.log(select_val);
if (select_val === 'Leverancier') {
$("#Klanttable").removeClass("hidden form-control");
}
else {
$("#Klanttable").addClass("hidden form-control");
$("#Klanttable").val("");
}
});
});
关于javascript - 向 JS 类添加一个引导类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52944024/