Mar*_*ris 4 javascript jquery bootstrap-4
我有一个引导复选框,问题是选中它时我无法获取它的值。下面的代码是我的复选框。
<div class="col-md-auto">
<div class="form-group">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" id="briskbusiness" value="1">
Brisk Business
<i class="input-frame"></i>
</label>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的 Jquery:
$(document).on('change','#briskbusiness',function() {
if(this.checked){
alert();
}
});
Run Code Online (Sandbox Code Playgroud)
我尝试使用单击并更改,但仍然不会显示警报。
这是我的复选框的外观。
小智 5
您的代码似乎工作正常。导入 jQuery 库时可能会出现问题
<script
src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"></script>
<div class="col-md-auto">
<div class="form-group">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" id="briskbusiness" value="1">
Brisk Business
<i class="input-frame"></i>
</label>
</div>
</div>
</div>
<script>
$(document).on('change','#briskbusiness',function() {
a = $("input[type='checkbox']").val();
if(this.checked){
alert(a);
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
检查上面的代码。
| 归档时间: |
|
| 查看次数: |
4826 次 |
| 最近记录: |