gpt4 book ai didi

javascript - PrintThis 不捕获选中的复选框

转载 作者:行者123 更新时间:2023-11-30 10:00:47 24 4
gpt4 key购买 nike

所以我使用 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/

最佳答案

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

关于javascript - PrintThis 不捕获选中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31816629/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com