javascript没有工作innerhtml

时间:2012-05-21 14:22:44

标签: javascript asp.net html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Login - Loja do Munícipe</title>
    <link rel="stylesheet" type="text/css" href="<%= stCSSFile %>" />
    <link href="../styles/cmm/main.css" rel="stylesheet" type="text/css" />
    <script language="javascript">

       function getbrowser () {
            var browser_info = {
                name: null,
            };

            if (navigator && (navigator.userAgent.toLowerCase()).indexOf("chrome") > -1) browser_info.name = "chrome";
            else if (navigator && (navigator.userAgent.toLowerCase()).indexOf("msie") > -1) browser_info.name = "ie";
            else if (navigator && (navigator.userAgent.toLowerCase()).indexOf("firefox") > -1) browser_info.name = "firefox";
            else if (navigator && (navigator.userAgent.toLowerCase()).indexOf("msie") > -1) browser_info.name = "other";

            if (browser_info.name == "ie" || browser_info.name =="firefox")
            {
            var linkinst = document.getElementById("ccbox");
                linkinst.innerHTML = "<div class=\"citizenCardCtr\" onmouseover=\"this.style.cursor='pointer';\" onclick=\"redirect();\"><h2>Autenticação com cartão do cidadão</h2> <p>Para escolher esta opção terá de ter em sua posse:</p><ul> <li>- Cartão do Cidadão;</li> <li>- Leitor do cartão, correctamente instalado no seu computador;</li> <li>- PIN da assinatura digital;</li> <li>- PIN da morada.</li></ul></div>";
                }
            else if (browser_info.name == "chrome")
                {
                var linkinst = document.getElementById("ccbox");
                linkinst.innerHTML = "<div class=\"citizenCardCtr\" onmouseover=\"this.style.cursor='pointer';\"><h2>Autenticação com cartão do cidadão</h2> <p> Esta funcionalidade não está desponivel no seu browser </div>";
                }


            }
    </script>
    <style type="text/css">
        .stylenumber
        {
            font-size: 14px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">

    <div id="mainCtr">
            <div class="boxesCtr">
                <div id="ccbox" style="font-size: 12px; color: #574529; font-family: Verdana; text-align:justify;"></div> 
            </div>
    </div>
    </form>
</body>
</html>

getbrowser功能不起作用...当我加载页面时,id =“ccbox”的div显示IE,Chrome或Firefox没有文字。

4 个答案:

答案 0 :(得分:2)

尝试在getbrowser

的定义之前添加此内容
window.onload = getbrowser;

答案 1 :(得分:1)

尝试在getbrowser函数定义下面添加此项:

window.onload=getbrowser;

答案 2 :(得分:1)

在定义getbrowser window.onload=getbrowser;

之前添加此内容

所以它看起来像这样。

<script language="javascript">
window.onload=getbrowser;
function getbrowser () {

答案 3 :(得分:-4)

将脚本放在页脚中。它会起作用。