函数在不同的浏览器中返回不同的值

时间:2014-07-24 16:15:58

标签: javascript jquery css cross-browser

我创建了一个函数,它返回数组中元素的选定css属性。但是,此阵列在Chrome和Firefox中有所不同。 小提琴:http://jsfiddle.net/9Jyx8/1/

这是功能:

function butunCSSyiAl (el,ozellikler) {
    var deger = new Array();
    for (var i = 0 ; i < ozellikler.length ; i++) {
        deger[i] = el.css(ozellikler[i]);
        if(ozellikler[i] == "width"){
        //alert(el.css(ozellikler[i]));
        }
    }
    return deger;
}



 var ozellikler = new Array('font-size','font-weight','font-style','color','text-transform','text-decoration','letter-spacing','word-spacing',  'line-height','text-align','vertical-align','direction','background-color','background-image','background-repeat','background-position','background-attachment','width','height','top','right','bottom','left','margin-top','margin-right','margin-bottom','margin-left','padding-top','padding-right','padding-bottom','padding-left','border-top-width','border-right-width','border-bottom-width','border-left-width','border-top-color','border-right-color','border-bottom-color','border-left-color','border-top-style','border-right-style','border-bottom-style','border-left-style','position','display','visibility','overflow-x','overflow-y','white-space','clip','float','clear','cursor','list-style-image');

有没有办法解决这个问题?

1 个答案:

答案 0 :(得分:4)

浏览器设置了自己的默认样式,因此您的数组在不同浏览器之间将具有不同的值。每个浏览器可能具有font-size,边距等的不同默认值。

相关问题