所以我使用PrintThis JQuery插件来打印表单字段,但由于某种原因,我无法让插件打印出对复选框所做的任何更改。当我单击“打印”时,唯一似乎要更改的复选框是默认情况下具有“已选中”属性的复选框。关于如何解决这个问题的任何想法?
HTML:
<body>
<div id="print">
<form>
<input id="option" type="checkbox" checked>
<label class="checkbox" for="option"> You are 18 years or older</label>
<br><br>
<input id="option2" type="checkbox">
<label class="checkbox" for="option2"> You have tested positive for something in your blood</label>
<br><br>
<input id="option3" type="checkbox">
<label class="checkbox" for="option3"> You have health-related kidney problems</label>
<br><br>
<input id="option4" type="checkbox">
<label class="checkbox" for="option4"> You have health-related skin problems</label>
<br><br>
<input id="option5" type="checkbox">
<label class="checkbox" for="option5"> You have a low platelet count</label>
</form>
</div>
<br>
<br>
<input id="printButton" type="button" value="Click here to download and print this checklist to review with your doctor." />
</body>
答案 0 :(得分:4)
不确定这里可能存在什么问题,但你可以通过明确设置已检查复选框的checked属性来绕过它。
$("input:button").click(function () {
$('input[type="checkbox"]').each(function() {
var $this = $(this);
if($this.is(':checked')) {
$this.attr('checked', true);
} else {
$this.removeAttr('checked');
}
});
$("#print").printThis({'importStyle': true});
});
<强> Check Fiddle 强>
答案 1 :(得分:0)
所以浏览plugin's source之后。看起来像是表单值的属性。我添加了它似乎工作。
$('#selector').printThis({formValues:true});