weixin_33698823 2016-04-20 11:36 采纳率: 0%
浏览 17

列印无效

I have a div that contains some input fields whose values are provided with jQuery. Also I copied some code I found to print them, but when I press the button to print, the values from the fields are empty.

Here is my code:

<script>
    $(document).ready(function() {
        $('#name').val("Bruce");
        $('#lastname').val("Lee");
        $('#age').val("35");
    });
</script>

<script>
    $(document).ready(function() {
       $("#printhem").click(function(){
           var divContents = $("#printedDiv").html();
           var printWindow = window.open('', '', 'height=700,width=900');

           printWindow.document.write('<html><head><title>PRINTED</title>');
           printWindow.document.write('</head><body >');
           printWindow.document.write(divContents);
           printWindow.document.write('</body></html>');
           printWindow.document.close();
           printWindow.print();
        });
    });
</script>

<div id="printedDiv"
    <input name="name" type="text" id="name">
    <input name="lastname" type="text" id="lastname">
    <input name="age" type="text" id="age">
    <div id="printhem">Print</div>
</div>
  • 写回答

2条回答 默认 最新

  • weixin_33717298 2016-04-20 11:41
    关注

    Use attr()

    $(document).ready(function() {
    $('#name').attr('value',"Bruce");
    $('#lastname').attr('value',"Lee");
    $('#age').attr('value',"35");
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置