PrintThis 不捕获选中的复选框

PrintThis Not Capturing Checked Checkboxes

所以我使用 PrintThis JQuery 插件来打印表单域,但由于某种原因我无法让插件打印出对复选框所做的任何更改。当我单击 "Print" 时,唯一出现变化的复选框是默认情况下具有 "checked" 属性 的复选框。关于如何解决此问题的任何想法?

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/

不确定这里可能是什么问题,但您可以通过为选中的复选框显式设置 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

所以在浏览完plugin's source之后。看起来表单值有一个 属性。我添加了它,它似乎有效。

$('#selector').printThis({formValues:true});

http://jsfiddle.net/wzp0e9r9/