jquery
  • firefox
  • google-chrome
  • 2010-01-13 44 views 0 likes 
    0

    我編寫了這段代碼,它在谷歌瀏覽器中運行良好,但是當涉及到Firefox和其他主流瀏覽器時,它甚至不會改變一點點:jQuery代碼正在使用谷歌瀏覽器,但不是Firefox,IE甚至是Safari瀏覽器

    jQuery("div[style*='line-height:25px']").contents(":not(nodeType!='1',br)").wrap("<div style='margin-bottom:9px;line-height:normal;margin-top:4px'>"); 
    jQuery("div[style*='line-height:25px'] br").remove(); 
    

    它可能看起來有點怪異,但它是我要解決一個非常令人沮喪的問題的事物,所以反正讓我給你關於系統的規範:

    • 的jQuery 1.3.2用noConflict()方法避免與原型的衝突$
    • Scriptaculous的1.7.1_beta3
    • 原型1.5.1
    • ,是的,我使用jQuery(document).ready()功能做的事情後,DOM已準備就緒。

    這些庫也嵌入在頁面上。

    對於建議: 我沒有養成這個頁面和其他一百個這樣的一個問題是網頁他們都是靜態頁面和使用shtml至少有一些共同的代碼。但我無法刪除任何這些庫,因爲這意味着我將不得不編輯大量頁面,並且花費數週時間。所以實際上我所看到的是像上面那樣的臨時解決方案。

    在此先感謝。

    部分HTML:

    <div style="font-size: 13px; line-height: 25px;"> 
        <!-- BULLETS MORE --> 
        <div style="line-height: normal;"> 
        Fine quality, full grain pebble leather 
        </div> 
        Smooth Classic Napa leather construction 
        <br /> 
        Lateral footprint with top access 
        <br /> 
        Durable belt clip 
        <br /> 
        Top flap with snap closure for added security 
        <br /> 
        Soft velvet lining with light protective layer 
        <br /> 
        Bottom push-through cutout for easy Motorola Droid removal 
        <br /> 
        Simple Scandinavian rounded design 
        <br /> 
        Sena craftsmanship and quality 
        <br /> 
    </div> 
    
    +0

    ,你能不能給我們整個HTML輸出(審查內容/必要時排除圖片),我們可以玩嗎? – 2010-01-13 20:55:50

    回答

    1

    如何略有改寫呢?

    jQuery("div").filter(lineHeight).contents(nonElementNodes).wrap("<div style='margin-bottom:9px;line-height:normal;margin-top:4px'>"); 
    
    jQuery("div").filter(lineHeight).find("br").remove(); 
    
    function lineHeight() { 
        return this.style.lineHeight == "25px"; 
    } 
    
    function nonElementNodes() { 
        return this.nodeType !== 1 || this.tagName !== 'BR'; 
    } 
    
    0

    我不認爲你的內容,選擇是否設置正確。你應該這樣做:

    jQuery("div[style*='line-height:25px']").contents(":not(br)").filter(function(){return this.nodeType != 1;}).wrap("<div style='margin-bottom:9px;line-height:normal;margin-top:4px'>"); 
    jQuery("div[style*='line-height:25px'] br").remove(); 
    
    +0

    它也沒有工作。並且'nodeType = 1'允許與Selector字符串一起使用。這裏是一個例子:http://tinyurl.com/ycanhl2 – Tarik 2010-01-13 21:12:15

    0

    不要在選擇使用',只是:

    jQuery("div[style*=line-height:25px]") 
    
    +0

    只是讓你知道,這不是解決方案,因爲即使jQuery建議使用'''它不會用這種方式:) – Tarik 2010-01-13 21:04:34

    0

    yikes。 jQuery允許你寫一些非常強大的查詢,但這並不意味着你應該這樣做。

    ,如果你有超過你應該添加在需要一些類和一些類選擇替換那些亂七八糟的HTML控件,它會在所有的瀏覽器,並以更快的速度啓動

    相關問題