【发布时间】:2018-01-31 05:51:09
【问题描述】:
我尝试在 Bootstrap 模式上删除 iCheck checked 状态,但我尝试了很多次,但都失败了。
我将 iCheck 用于输入类型复选框和单选。
所以这是模态代码:
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<form role="form" id="form-swab" class="form-horizontal" action="tambah">
<div class="box-body">
<div class="form-group">
<label for="swab_parameter" class="col-sm-3 control-label">Parameter Uji</label>
<div class="col-sm-8">
<label>
<input type="checkbox" name="swab_parameter[]" id="swab_parameter_tpc" value="TPC">
TPC
</label>
<label>
<input type="checkbox" name="swab_parameter[]" id="swab_parameter_coliform" value="Coliform">
Coliform
</label>
</div>
</div>
<div class="form-group" id="hasil_swab_tpc">
<label for="swab_tpc" class="col-sm-3 control-label">Hasil TPC</label>
<div class="col-sm-8">
<input type="text" id="swab_tpc" name="swab_tpc" class="form-control" placeholder="Hasil Analisa TPC">
</div>
</div>
<div class="form-group" id="hasil_swab_coliform">
<label for="swab_coliform" class="col-sm-3 control-label">Hasil Coliform</label>
<div class="col-sm-8">
<input type="text" id="swab_coliform" name="swab_coliform" class="form-control" placeholder="Hasil Analisa Coliform">
</div>
</div>
</div>
<!-- /.box-body -->
<input type="hidden" name="swab_ID" id="swab_ID" />
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" id="button-close-swab" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="submit-swab">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal swab -->
我用hashchange 切换模式(jquery.ba-bbq.min.js 来自https://github.com/cowboy/jquery-bbq)。这个 js 在页脚中加载。
Javascript 代码(在页脚中加载为site.js):
var path = window.location.pathname;
var host = window.location.hostname;
$(function(){
$(window).hashchange(function(){
var hash = $.param.fragment();
if(hash == 'tambah'){
if(path.search('mikro/swab') > 0){
$('#myModal .modal-header .modal-title').text('Input Data Swab');
$('#myModal .modal-footer #submit-swab').text('Simpan');
$('#myModal #form-swab').attr('action','tambah');
}
// other else if
}
// other else if
});
$(window).trigger('hashchange');
$('#myModal').on('hidden.bs.modal', function(){
window.history.pushState(null,null,path);
$('#myModal form').find("input[type=text], input[type=email], input[type=password], textarea, select").val("");
$('#myModal form').show();
$('input').iCheck('uncheck');
});
});
$('#swab_parameter_tpc, #swab_parameter_coliform').iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue',
increaseArea: '20%' // optional
});
$('#swab_parameter_tpc').on('ifChecked', function(event){
$('#hasil_swab_tpc').show('slow');
});
$('#swab_parameter_coliform').on('ifChecked', function(event){
$('#hasil_swab_coliform').show('slow');
});
$('#swab_parameter_coliform').on('ifUnchecked', function(event){
$('#hasil_swab_coliform').hide('slow');
});
$('#swab_parameter_ym').on('ifUnchecked', function(event){
$('#hasil_swab_ym').hide('slow');
});
问题是:当我打开modal时,勾选checkbox并关闭modal,然后再次打开modal,checkbox还是checked状态,应该是重新取消勾选。我尝试使用$('input').iCheck('uncheck'); 但不起作用。
我的代码有问题吗?
【问题讨论】:
标签: javascript twitter-bootstrap checkbox bootstrap-modal icheck