0

我在创建动态表时遇到问题,该表会Internet Explorer 6因为json使用而起作用。我实际上找到了不错的工作。我想实现html根据用户浏览器版本显示不同表格的脚本。
这是我的浏览器版本检测器脚本:

<script>
    function getInternetExplorerVersion()
    // Returns the version of Windows Internet Explorer or a -1
    // (indicating the use of another browser).
    {
        var rv = -1; // Return value assumes failure.
        if (navigator.appName == 'Microsoft Internet Explorer'){
            var ua = navigator.userAgent;
            var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
            if (re.exec(ua) != null)
                rv = parseFloat( RegExp.$1 );
        }
        return rv;
    }
function checkIEVersion()
{
   var ver = getInternetExplorerVersion();
   if ( ver> -1 )
   {
      if ( ver == 6.0 ){
    <? echo"<TABLE id=\"tableToModify\" width=\"1100px\" border=\"1\"  class='list questionaire' width='600'>";
    echo" <TR class='columndesc'>";
    echo"<TD WIDTH=\"50%\">Col1<font color=\"red\">*</font></TD>";
    echo"<TD WIDTH=\"50%\">Col1<font color=\"red\">*</font></TD>";

    echo  "</TABLE>";   ?>     
   }
    echo"<TABLE id=\"tableToModify\" width=\"1100px\" border=\"1\"  class='list questionaire' width='600'>";
    echo" <TR class='columndesc'>";
    echo"<TD WIDTH=\"22%\">Col1<font color=\"red\">*</font></TD>";
    echo"<TD WIDTH=\"22%\">col2<font color=\"red\"></font></TD>";
    echo"<TD WIDTH=\"22%\">col3<font color=\"red\"></font></TD>";
    echo"<TD WIDTH=\"22%\">col4<font color=\"red\">*</font></TD>";
    echo" <TD WIDTH=\"22%\">col5<font color=\"red\">*</font></TD>";
    echo" <TD WIDTH=\"12%\"> col6<font color=\"red\">*</font></TD>";
    echo  "</TABLE>";

?>
}
}
checkIEVersion();
</script>

但现在我得到了 errorz : uncaught syntax exception。我确实意识到这php - echo是原因,但我无法提出另一个想法,尤其是当我希望这张桌子显示在我想要的位置时:



Some html fields, imput tables buttons forms


Script I posted above


other form fields etc

总结一下,我HTML在脚本上方和下方都有代码。
谁能给我一个提示如何解决我的问题?

4

1 回答 1

3

我相信这就是您所需要的(可能需要根据您的需要进行调整):

function getInternetExplorerVersion()
// Returns the version of Windows Internet Explorer or a -1
// (indicating the use of another browser).
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null) rv = parseFloat(RegExp.$1);
    }
    return rv;
}

function checkIEVersion() {
    var ver = getInternetExplorerVersion();
    if (ver > -1) {
        if (ver == 6.0) {
            $html = "<TABLE id=\"tableToModify\" width=\"1100px\" border=\"1\"  class='list questionaire' width='600'>" +
            "<TR class='columndesc'>" +
            "<TD WIDTH=\"50%\">Col1<font color=\"red\">*</font></TD>" +
            "<TD WIDTH=\"50%\">Col1<font color=\"red\">*</font></TD>" +
            "</TABLE>";
        } else {
            $html = "<TABLE id=\"tableToModify\" width=\"1100px\" border=\"1\"  class='list questionaire' width='600'>" +
            "<TR class='columndesc'>" +
            "<TD WIDTH=\"22%\">Col1<font color=\"red\">*</font></TD>" +
            "<TD WIDTH=\"22%\">col2<font color=\"red\"></font></TD>" +
            "<TD WIDTH=\"22%\">col3<font color=\"red\"></font></TD>" +
            "<TD WIDTH=\"22%\">col4<font color=\"red\">*</font></TD>" +
            "<TD WIDTH=\"22%\">col5<font color=\"red\">*</font></TD>" +
            "<TD WIDTH=\"12%\"> col6<font color=\"red\">*</font></TD>" +
            "</TABLE>";
        }
        document.write($html);
    }
}
checkIEVersion();
于 2013-04-10T08:18:55.570 回答