簡體   English   中英

使用JS的多個內聯樣式,如何設置后備廣告?

[英]Multiple inline styles with JS, how to set fallback?

因此,如果我要使用CSS將其編寫為類,則會得到類似以下內容的信息:

.cursorChange {
    cursor: move; /*IE*/
    cursor: grabbing; /*Mozilla*/
    cursor: -webkit-grabbing; /*Chrome*/
}

但是,我想在抓取元素時將這些樣式與javascript內聯應用。 現在這樣的一行:

document.getElementById('foo').style.cursor = "move";

顯然可行,但是如何向該節點添加一個以上的值? 如果我只是寫抓取,IE沒有回退,mozzila也無法識別它,是否可以在此處添加多個值?

PS無法更改整個樣式字符串,因為它上面僅包含光標。 我需要這是內聯的,而不是由於css的編寫方式的類。

這樣的事情怎么樣:

if(navigator.userAgent.indexOf("Chrome") != -1 ){ // Chrome
        document.getElementById('foo').style.cursor = "-webkit-grabbing";
}else if(navigator.userAgent.indexOf("Firefox") != -1 ){ //FireFox
        document.getElementById('foo').style.cursor = "grabbing";
}else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )){ //IE
       document.getElementById('foo').style.cursor = "move";
}    

您可以嘗試以下方式:

var isIE = /*@cc_on!@*/false || !!document.documentMode;
var isMozilla = typeof InstallTrigger !== 'undefined';  
var isChrome = !!window.chrome && !!window.chrome.webstore;

if(isIE) {
    document.getElementById('foo').style.cursor = "move";
}
if(isMozilla) {
    document.getElementById('foo').style.cursor = "grabbing";
}
if(isChrome) {
    document.getElementById('foo').style.cursor = "-webkit-grabbing";
}

另外,您還可以從此處獲得更多瀏覽器選項: 如何檢測Safari,Chrome,IE,Firefox和Opera瀏覽器?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM