我正在使用 javascript 根据时间切换表格。但是我在 DW 中遇到错误。
<script type="text/JavaScript">
<!--
function changeWebsite() {
var currentTime = new Date().getHours();
if (7 <= currentTime&¤tTime < 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('
最佳答案
- JavaScript 不支持多行字符串。
字符串中有未转义的单引号(用单引号分隔)。
例如,您必须更改: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/