语句中的结构违反一个或多个语法规则时,会出现JavaScript语法错误。出现之后需要检查模板中本页的代码,看是否有语法错误,JS调用的错误,缺少标记的错误,还有个就是记数器代码的错误。这几个要十分仔细,其实也这不是什么大问题。
javascript严格区分大小写 所以 eLse不对 改为else
host=L 这样写是赋值 如过比较他俩是否相等则这样写 host==L
下面是详细代码:
<!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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=UTF-8">
<title>Document</title>
</head>
<body>
<script>
var L1 = 'a.com'
var L2 = 'b.om'
var L3 = 'c.com'
var L4 = 'd.om'
var L5 = 'e.com'
var L6 = 'f.om'
var L7 = 'g.com'
var L8 = 'h.om'
var L9 = 'i.com'
var L10 = 'j.om'
var host = window.Location.host
if (host==L1){document.write("<a href=\"http://www.a.com/\">a</a>")}
else if (host==L2)
{document.write("<a href=\"http://www.b.com/\">b</a>")}
else if (host==L3)
{document.write("<a href=\"http://www.c.com/\">c</a>")}
else if (host==L4)
{document.write("<a href=\"http://www.d.com/\">d</a>")}
else if (host==L5)
{document.write("<a href=\"http://www.e.com/\">e</a>")}
else if (host==L6)
{document.write("<a href=\"http://www.f.com/\">f</a>")}
else if (host==L7)
{document.write("<a href=\"http://www.g.com/\">g</a>")}
else if (host==L8)
{document.write("<a href=\"http://www.h.com/\">h</a>")}
else if (host==L9)
{document.write("<a href=\"http://www.i.com/\">i</a>")}
else if (host==L10)
{document.write("<a href=\"http://www.j.com/\">j</a>")}
</script>
</body>
</html>