2010-05-23 27 views
1

我有一个函数编辑问题编辑类样式属性 - 问题是与IE

不幸的是IE浏览器似乎并不喜欢它一类的样式属性,但它并没有给我一个错误。

有谁知道这个问题是什么?

在此先感谢

function myRemoveElement(id) { 
    var Node = document.getElementById(id); 
    Node.parentNode.removeChild(Node); 
} 

function boolyChangeFoo(width1, width2, width3, width4) { 
    if(typeof style == 'undefined') { 
     var append = true; 
     myStyle = document.createElement('style'); 
    } else { 
     while (myStyle.hasChildNodes()) { 
      myStyle.removeChild(myStyle.firstChild); 
     } 
    } 
    if (document.getElementById('my_custom_styles')) 
    { 
     myRemoveElement('my_custom_styles'); 
    } 
    var head = document.getElementById('myltd_popup_1'); 
    var rules = document.createTextNode('.my_price_comp_inner { width: ' + width1 + '}' + 
     '.merch_coupons_summary { width: ' + width2 + '}' + 
     '.merch_coupons_data { width: ' + width3 + '}' + 
     '.my_coupon_prod_item { width: ' + width4 + '}' 
    ); 

    myStyle.setAttribute('type','text/css'); 
    myStyle.setAttribute('id', 'my_custom_styles'); 
    if(myStyle.styleSheet) { 
     myStyle.styleSheet.cssText = rules.nodeValue; 
    } else { 
     myStyle.appendChild(rules); 
    } 
    //alert(myStyle); 
    if(append === true) head.appendChild(myStyle); 
} 
+0

什么版本的IE?它在FF中工作吗? – Marthin 2010-05-23 19:53:56

+0

我已经在7和8中尝试过了 - 它可以在ff和chrome中工作 – Nick 2010-05-23 19:56:56

+0

什么是“style”变量应该做的?它从哪里设置? – Pointy 2010-05-23 20:10:55

回答

0

@Pointy - 我并不真的需要顶部

function myRemoveElement(id) { 
    var Node = document.getElementById(id); 
    Node.parentNode.removeChild(Node); 
} 

function boolyChangeFoo(width1, width2, width3, width4) { 
     var append = true; 
     myStyle = document.createElement('style'); 
    if (document.getElementById('my_custom_styles')) 
    { 
     myRemoveElement('my_custom_styles'); 
    } 
    var head = document.getElementById('myltd_popup_1'); 
    var rules = document.createTextNode('.my_price_comp_inner { width: ' + width1 + '}' + 
     '.merch_coupons_summary { width: ' + width2 + '}' + 
     '.merch_coupons_data { width: ' + width3 + '}' + 
     '.my_coupon_prod_item { width: ' + width4 + '}' 
    ); 

    myStyle.setAttribute('type','text/css'); 
    myStyle.setAttribute('id', 'my_custom_styles'); 
    if(myStyle.styleSheet) { 
     myStyle.styleSheet.cssText = rules.nodeValue; 
    } else { 
     myStyle.appendChild(rules); 
    } 
    //alert(myStyle); 
    if(append === true) head.appendChild(myStyle); 
} 
+0

也var boolyStyle;被设置在功能之外 – Nick 2010-05-23 20:23:52