因此,我使用PrintThis JQuery插件来打印表单字段,但由于某种原因,我无法让插件打印出对复选框所做的任何更改。当我单击"Print“时,唯一出现更改的复选框是默认具有”选中“属性的复选框。有什么办法解决这个问题吗?
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>JSFiddle:http://jsfiddle.net/Hybridx24/bxtpv26x/
发布于 2015-08-04 18:35:34
不确定这里的问题可能是什么,但您可以通过显式设置选中的复选框的复选属性来解决这个问题。
$("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});
});检查Fiddle
发布于 2015-08-04 18:43:03
所以在浏览了插件源之后。看起来表单值有一个属性。我把它加进去了,看起来很管用。
$('#selector').printThis({formValues:true});
http://jsfiddle.net/wzp0e9r9/
https://stackoverflow.com/questions/31816629
复制相似问题