2011-06-01 21 views
3

我在打印多個選擇時忽略了選擇邊框,IE9出現問題。IE9在打印時出現多個選擇溢出

下面是如何重現問題:

  1. 打開IE9在Windows 7
  2. 前往W3Schools的的multiple select edit page
  3. 現在突出顯示選項並複製/粘貼,直到出現一長串重複項。
  4. 然後刪除尺寸屬性。
  5. 單擊「編輯並單擊我」,以便重新加載頁面,並且您現在可以在第二個面板中選擇已修改的選擇。
  6. 現在,打印文檔(甚至使用XPS查看器)。

對我來說,所有的選項都打印在頁面上,即使select只有4個選項元素高。如果您將「size」屬性保留爲默認值2,這種情況仍然會在某種程度上發生,但在更改或刪除它時更加明顯。

是否有其他人遇到過這種情況?這是一個IE錯誤?有誰知道解決方法?

+0

沒有太大的幫助,但我運行到這一點。我試過指定高度和「溢出:隱藏」無濟於事...... – 2011-09-01 17:23:42

+0

我很想看到這個答案 - 現在有同樣的問題。 – 2012-07-30 19:00:21

回答

1

似乎有不爲這方面的任何CSS的解決方案。相反,我編寫了一個小型jQuery腳本,將<select multiple>內容複製到<div>中,以便可以打印它。然後,我應用了一些CSS,使其看起來像一個選擇,並且只在實際打印時顯示副本。

腳本:

//jQuery required 
$(function() { 
    if(!$.browser.msie) return false; 
    $('select[multiple]').each(function() { 
    $lPrintableDiv = $('<div data-for="' + this.id + '" />').addClass($(this).attr('class')).addClass('printable'); 

    //update printable on changes 
    $(this).after($lPrintableDiv).change(function($aEvent){ 
     updatePrintable($aEvent.target); 
    }); 

    //run once on load 
    updatePrintable(this); 
    }); 
}); 

function updatePrintable($aTarget) { 
    var $lSelect = $($aTarget); 
    var $lSelected = $($aTarget).val(); 
    var $lPrintable = $('[data-for="'+$aTarget.id+'"]'); 

    $($lPrintable).width($lSelect.width()).height($lSelect.height()); 
    $($lPrintable).html(''); 

    $($aTarget).children().each(function($lElm){ 
    $lVal = $(this).val(); 
    $lLabel = $('<label />').text($lVal); 
    $lOption = $('<input type="checkbox" />').val($lVal); 

    if($(this).is(':selected')) 
    $lOption.prop('checked', true); 

    $lPrintable.append($lOption).append($lLabel); 
    }); 
} 

CSS:

.printable { 
    border: 1px solid grey; 
    display: none; 
    overflow: auto; 
} 

    .printable label { 
     display: block; 
     font: .8em sans-serif; 
     overflow: hidden; 
     white-space: nowrap; 
    } 

    .printable [type="checkbox"] { 
     display: none; 
    } 

    .printable [type="checkbox"]:checked + label { 
     background: #3399ff; 
     color: white; 
    } 

@media print { 
    select[multiple] { display: none; } 
    .printable { display: inline-block; } 
    .printable [type="checkbox"]:checked + label { background: grey; } 
} 

另見jsFiddleoriginal post有關此修復程序

+0

我想說這是一個非常好的解決方法,但如果IE可以一起行動,我會喜歡它。 – spizzat2 2012-10-26 18:55:18