PrintThis Not Capturing Checked Checkbox

时间:2015-08-04 18:28:12

标签: javascript jquery printthis

所以我使用PrintThis JQuery插件来打印表单字段,但由于某种原因,我无法让插件打印出对复选框所做的任何更改。当我单击“打印”时,唯一似乎要更改的复选框是默认情况下具有“已选中”属性的复选框。关于如何解决这个问题的任何想法?

HTML:

<body>

<div id="print">
  <form>
    <input id="option" type="checkbox" checked>
    <label class="checkbox" for="option">&nbsp;&nbsp;You are 18 years or older</label>
    <br><br>
    <input id="option2" type="checkbox">
    <label class="checkbox" for="option2">&nbsp;&nbsp;You have tested positive for something in your blood</label>
    <br><br>
    <input id="option3" type="checkbox">
    <label class="checkbox" for="option3">&nbsp;&nbsp;You have health-related kidney problems</label>
    <br><br>
    <input id="option4" type="checkbox">
    <label class="checkbox" for="option4">&nbsp;&nbsp;You have health-related skin problems</label>
    <br><br>
    <input id="option5" type="checkbox">
    <label class="checkbox" for="option5">&nbsp;&nbsp;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/

2 个答案:

答案 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});

http://jsfiddle.net/wzp0e9r9/