根据它的颜色改变颜色......取2

时间:2015-06-15 09:40:12

标签: javascript html css

与我上周的问题类似here.

同样,如果值为真,我需要返回绿色值,如果值为假则需要返回红色。逻辑是正确的,它只是一种不起作用的造型,但我不确定为什么?

JS

    var getAcrobatInfo = function () {
        var noPDF = 'No PDF viewer installed';

        var getBrowserName = function () {
            return this.name = this.name || function () {
                var userAgent = navigator ? navigator.userAgent.toLowerCase() : "other";

                if (userAgent.indexOf("chrome") > -1) {
                    return "chrome";
                } else if (userAgent.indexOf("safari") > -1) {
                    return "safari";
                } else if (userAgent.indexOf("msie") > -1 || navigator.appVersion.indexOf('Trident/') > 0) {
                    return "ie";
                } else if (userAgent.indexOf("firefox") > -1) {
                    return "firefox";
                } else {
                    //return "ie";
                    return userAgent;
                }
            }();
        };

        var getActiveXObject = function (name) {
            try {
                return new ActiveXObject(name);
            } catch (e) { }
        };

        var getNavigatorPlugin = function (name) {
            for (key in navigator.plugins) {
                var plugin = navigator.plugins[key];
                if (plugin.name == name) return plugin;
            }
        };

        var getPDFPlugin = function () {
            return this.plugin = this.plugin || function () {
                if (getBrowserName() == 'ie') {
                    return getActiveXObject('AcroPDF.PDF') || getActiveXObject('PDF.PdfCtrl');
                } else {
                    return getNavigatorPlugin('Adobe Acrobat') || getNavigatorPlugin('Chrome PDF Viewer') || getNavigatorPlugin('WebKit built-in PDF');
                }
            }();
        };

        var isAcrobatInstalled = function () {
            return !!getPDFPlugin();
        };

        var getAcrobatVersion = function () {
            try {
                var plugin = getPDFPlugin();

                if (getBrowserName() == 'ie') {
                    var versions = plugin.GetVersions().split(',');
                    var latest = versions[0].split('=');
                    return parseFloat(latest[1]);
                }

                if (plugin.version) return parseInt(plugin.version);
                return plugin.name
            } catch (e) {
                return noPDF;
            }
        }

        return {Acrobat: isAcrobatInstalled()};
    };

    var info = getAcrobatInfo();
    var pdf = document.getElementById('acrobat');

    if (info.Acrobat) {
        pdf.classList.add('green');
        pdf.innerHTML = 'True';
    }
    else {
        pdf.classList.add('red');
        pdf.innerHTML = 'False';
    }    
}

HTML

    <tr>
        <td>PDF Viewer Enabled:</td>
        <td id="acrobat"></td>
   </tr>

CSS

#pdf.green {
  color: #33CC33;
  font-weight: bold;
}
#pdf.red {
  color: #FF0000;
  font-weight: bold;
}

0 个答案:

没有答案