1

So I am using the PrintThis JQuery plugin in order to print a form field, but for some reason I am unable to have the plugin print out any changes made to the checkboxes. When I click "Print", the only checkbox that appears to change is one that has a "checked" property by default. Any ideas on how to fix this?

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/

4

2 回答 2

4

不确定这里可能存在什么问题,但您可以通过显式设置已选中复选框的选中属性来解决此问题。

$("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});
});

检查小提琴

于 2015-08-04T18:35:34.937 回答
0

所以在浏览了插件的源代码之后。看起来有一个表单值的属性。我添加了它,它似乎工作。

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

http://jsfiddle.net/wzp0e9r9/

于 2015-08-04T18:43:03.707 回答