javascript - 这个javascript有什么问题?

标签 javascript

我正在使用 javascript 根据时间切换表格。但是我在 DW 中遇到错误。

       <script type="text/JavaScript">
<!--
function changeWebsite() {
var currentTime = new Date().getHours();    

 if (7 <= currentTime&&currentTime < 18) {
       document.write('  <table id="Table_01" width="200" height="400" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td>
            <img src="http://itsnotch.com/tumblr/images/websitelist_tumblr_VC01.png" width="200" height="45" alt=""></td>
    </tr>
    <tr>
        <td>
            <a href="http://www.itsnotch.com"
                onmouseover="window.status='Visit My Biography Website';  return true;"
                onmouseout="window.status='';  return true;">
                <img src="http://itsnotch.com/tumblr/images/websitelist_tumblr_VC02.png" width="200" height="75" border="0" alt="ItsNotch.com"></a></td>
    </tr>
    <tr>
        <td>
            <a href="http://www.notchtheguru.com"
                onmouseover="window.status='My Tumblr';  return true;"
                onmouseout="window.status='';  return true;">
                <img src="http://itsnotch.com/tumblr/images/NotchTheGuru.comVC.png" width="200" height="119" border="0" alt="Tumblr"></a></td>
    </tr>
    <tr>
        <td>
            <a href="http://www.bignotch.com"
                onmouseover="window.status='Welcome to My Music Website';  return true;"
                onmouseout="window.status='';  return true;">
                <img src="http://itsnotch.com/tumblr/images/websitelist_tumblr_VC04.png" width="200" height="161" border="0" alt="NotchTheGuru.com"></a></td>
    </tr>
</table>
<br>
 ');
      }

       else {
       document.write(' <table id="Table_01" width="200" height="400" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td>
            <img src="http://itsnotch.com/tumblr/images/websitelist_tumblr_01.png" width="200" height="45" alt=""></td>
    </tr>
    <tr>
        <td>
            <a href="http://www.itsnotch.com"
                onmouseover="window.status='Visit My Biography Website';  return true;"
                onmouseout="window.status='';  return true;">
                <img src="http://itsnotch.com/tumblr/images/websitelist_tumblr_02.png" width="200" height="75" border="0" alt="ItsNotch.com"></a></td>
    </tr>
    <tr>
        <td>
            <a href="http://www.notchtheguru.com"
                onmouseover="window.status='My Tumblr';  return true;"
                onmouseout="window.status='';  return true;">
                <img src="http://itsnotch.com/tumblr/images/NotchTheGuru.com.png" width="200" height="119" border="0" alt="Tumblr"></a></td>
    </tr>
    <tr>
        <td>
            <a href="http://www.bignotch.com"
                onmouseover="window.status='Welcome to My Music Website';  return true;"
                onmouseout="window.status='';  return true;">
                <img src="http://itsnotch.com/tumblr/images/websitelist_tumblr_04.png" width="200" height="161" border="0" alt="NotchTheGuru.com"></a></td>
    </tr>
</table>
<br>
 ');
      }

}

changeWebsite();
-->

错误在第 7 行 'document.write('

最佳答案

  1. JavaScript 不支持多行字符串。
  2. 字符串中有未转义的单引号(用单引号分隔)。
    例如,您必须更改:

    onmouseover="window.status='Visit My Biography Website'; 
    

    到:

    onmouseover="window.status=\'Visit My Biography Website\';
    

有关详细信息,请通过 JSLint 运行您的代码.

WARNING: JSLint will hurt your feelings.

关于javascript - 这个javascript有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5223614/

相关文章:

javascript - 专业网站

javascript - 使用 xpath 获取并打印出元素

javascript - 如果没有发生按键事件,js 按键事件和操作之间的时间间隔

javascript - 函数隐藏在javascript中

javascript - JQuery 回调未执行?

javascript - 为什么 testmysite 声称我的网站速度很慢?

php javascript 压缩器

javascript - AngularJS ng-repeat 在 tbody 中不起作用

javascript - 转义所有输入类型的 TEXT 上的所有特殊字符以防止 XSS

javascript - 使用其 ID 定位其他 iframe