<script>
$("#filter").on("shown.bs.popover",function(){
$(".popover-content input[type=checkbox]").on("click",function(){
if(this.checked)
{
this.setAttribute("checked","checked");
}
else
{
this.removeAttribute("checked");
}
$("#customdiv").html($(".popover-content").html());
});
});
function fieldsFilter(flag,value,chkClass)
{
var checkedfields = new Array();
$('.'+chkClass).each(function()
{
if($(this).is(':checked'))
{
checkedfields.push($(this).val());
document.getElementById('scatFilters').value;
document.getElementById('ssrcFilters').value;
}
else
{
document.getElementById('scatfFilters').value='';
document.getElementById('ssrcfFilters').value = '';
}
});
$('#'+flag+'Filters').val(checkedfields);
}
</script>
<div id="content" class="content">
<div class="container">
<div class="email-btn-row hidden-xs inbox-actions" id="inbox-actions">
<a href="javascript:;" class="btn btn-sm btn-success" id='filter'><i class="fa fa-filter"></i></a>
<div class='hide' id='customdiv'>
<div class="panel-group">
<button href="#" class="btn btn-link btn-sm" onclick="clearFilter()">Clear Filter</button>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse1" aria-expanded="true" aria-controls="collapse1">
<i class="more-less glyphicon glyphicon-plus"></i>
Representatives
</a>
</h4>
</div>
<div id="collapse1" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
<?php
foreach($rep_options as $rep_id => $rep_name){?>
<input type="checkbox" class="RepClicked" name="rep_<?=$rep_id?>" id="rep_<?=$rep_id?>" onchange="fieldsFilter('rps',this.value,'RepClicked');" value="<?=$rep_id?>" <? if(in_array($rep_id,$rep_name)) { echo "checked"; } ?>/>
<span style="font-size:12px;"><?=$rep_name?></span>
<br/>
<?php }?>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse2" aria-expanded="true" aria-controls="collapse2">
<i class="more-less glyphicon glyphicon-plus"></i>
Status
</a>
</h4>
</div>
<div id="collapse2" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
<?php
foreach($status_options as $status_id => $status){?>
<input type="checkbox" class="StatusClicked" name="status_<?=$status_id?>" id="status_<?=$status_id?>" onchange="fieldsFilter('sts',this.value,'StatusClicked');" value="<?=$status_id?>" <? if(in_array($status_id,$status)) { echo "checked"; } ?>/>
<span style="font-size:12px;"><?=$status?></span>
<br/>
<?php }?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="email-btn-row hidden-xs inbox-actions" id="inbox-actions" style="float:right">
<form id="allFilters" name="" class="" method="post" action="<?php echo base_url();?>missed_call_campaign/export">
<div class="row">
<div class="col-md-6">
</div>
<div class="col-md-6">
<input type="text" name="rpsFilters" class='hiddenFld' id="rpsFilters" value="<?=implode(',',$rep_id);?>" placeholder="rps"/>
<input type="text" name="stsFilters" class='hiddenFld' id="stsFilters" value="<?=implode(',',$status_id);?>" placeholder="sts"/>
</div>
</div>
</form>
</div>
</div>
</div>
如果我选中弹出窗口中的复选框,文本框将保留两次值,实际上我想要的是文本框应该一次获取该值。上面的jquery脚本用于在关闭弹出框时保留选中的复选框值。由于第一个 jquery 脚本,文本框中的值被取了两次。对不起我的英语。任何人都可以帮我摆脱困境在这里输入图像描述
将你的checkedfields.push($(this(.val(((行包装在一个条件中 喜欢
if(checkedfields.indexOf($(this).val())==-1){
checkedfields.push($(this).val());
}