我在创建动态表时遇到问题,因为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
代码。
任何人都可以给我一个如何解决问题的提示吗?
答案 0 :(得分: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();