简体   繁体   中英

jQuery Print Preview Plugin not working with <h:commandLink>

I am trying to use jQuery Print Preview Plugin to show the prieview of a JSF page before printing it.

First I tried a demo with plain HTML tags.

<script src="../js/jquery.print-preview.js" type="text/javascript"
                    charset="utf-8"></script>
                <script type="text/javascript">
                    var $j = jQuery.noConflict();

                    $j(function() {
                                alert("hai");
                                /*
                                 * Initialise print preview plugin
                                 */
                                 $j('.print-preview').printPreview();
                                 alert("bye");

                            });
                </script>

                <div id="header" class="container_12">
                     <a class="print-preview">Print this Page</a>
                </div> 

I works correctly and the print -preview modal dailog is opened.

However,when i try replacing the <a> tag with <h:commandLink> the $(this).bind('click', function(e) within the print-preview.js is not triggered.

<h:form id="printForm">
                <script src="../js/jquery.print-preview.js" type="text/javascript"
                    charset="utf-8"></script>
                <script type="text/javascript">
                    var $j = jQuery.noConflict();

                    $j(function() {
                                alert("hai");
                                /*
                                 * Initialise print preview plugin
                                 */
                                 $j('.print-preview').printPreview();
                                 alert("bye");

                            });
                </script>

                <div id="header" class="container_12">
                <h:commandLink id="sample" value="Print this page" styleClass="print-preview"/> 

                </div> 
</h:form>

I even tried using $j('printForm\\\\:sample').printPreview(); , but still it is not working.

Am I doing something wrong?

我将<h:commandLink>替换为<p:commandLink> ,并且jQuery Print Preview插件现在可以正常工作了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM