使用jQuery打印HTML表单 [英] Printing an HTML form using jQuery

查看:443
本文介绍了使用jQuery打印HTML表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有HTML表单,需要打印(HardCopy)特定区域.

I am having an HTML form, and I need to print(HardCopy) particular area..

问题是我无法获取表格上的Text1和Text2值.由于我需要在HTML表单中填充一些值,因此在单击打印时应将其打印为硬拷贝.

The problem is I am unable to get the form Text1 and Text2 values on the. Since I need that HTML form to be filled with some value, while clicking print it should print as hardcopy.

        <script type="text/javascript">
            $(document).ready(function(){
                $("#print").click(function(){
                   alert($('#click').html());
                   // It shows only form elements; I need a form typed element too. How?
                   window.print();
                });
            });
        </script>
    </head>
    <body>
        <form id="click">
            Text1: <input id="l" type="text" />
            Text2: <input id="m" type="text"/>
            <input id="print" type="button" value="Print-Me"/>
        </form>
    </body>
</html>

推荐答案

据我了解,您需要在text1和text2输入字段中键入的文本.您可以使用.val()函数执行此操作,如下所示:

From what I can understand, you want the text that is typed in the text1 and text2 input fields. You can do so with the .val() function, like this:

$("#print").click(function(){
    alert($('#l').val() + '\n' + $('#m').val());
    window.print();
});

这篇关于使用jQuery打印HTML表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆