【问题标题】:Print element background css is not overriden after partial page update部分页面更新后不覆盖打印元素背景 css
【发布时间】:2011-11-17 23:33:11
【问题描述】:

我正在使用 jquery printElement 插件来打印我的视图的 div。目前它工作正常,但如果我用部分视图更新 div html,覆盖 css 似乎不起作用。

我的 html 构造:

<div id="shopfoods">
  <div id="shoplistcontent">
    <table id="shopfoodtable">

我得到了 shopfoods div 的背景图片,但我不希望背景显示在打印中,所以我用另一个 css 覆盖了打印:

$('#printitem').click(function () {
        $('#shopfoods').printElement({
            pageTitle: 'Your Shop List.html',
            leaveOpen: true,
            printMode: 'popup',
            overrideElementCSS: ['../../Content/PrintShopList.css']
        });
    });

这很好用,但如果我确实显示其他导致部分页面更新的操作,如下所示:

  // ... some ajax call
  success: function (result) {
      $('#shopfoods').html(result);
  }

更新后,如果我再次单击打印,打印将包括 shopfoods 的背景图像。 (但是,print.css 中的其他样式也可以)

我不知道这里出了什么问题,是单击功能、ajax、css 还是插件错误?

【问题讨论】:

    标签: jquery css printing


    【解决方案1】:

    当您重新创建 #shopfoods(通过 ajax)时,您之前对 printElement 的插件初始化可能会丢失。

    也许你需要把 $('#printitem').click(...) 改成 $('#printitem').live("click",...)

    看看这个:http://api.jquery.com/live/

    【讨论】:

    • 我认为这是正确的。虽然我需要指出As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live().
    猜你喜欢
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 2014-03-31
    • 2016-09-26
    • 1970-01-01
    • 1970-01-01
    • 2015-07-29
    • 2020-12-11
    相关资源
    最近更新 更多