js注释问题

g592010667 2015-08-24 08:16:46
下面这个能正确运行
<html>
<head>
<script type="text/javascript">
<!--
function reload(){
location.replace("http://baidu.com");
}
//-->
</script>
</head>
<body onload="reload()"></body>
</html>


但是如果删除一行js就不能被解析出来
<html>
<head>
<script type="text/javascript">
<!-- function reload(){
location.replace("http://baidu.com");
}
//-->
</script>
</head>
<body onload="reload()"></body>
</html>


这是什么原因。。。。
...全文
162 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
天际的海浪 2015-08-24
  • 打赏
  • 举报
回复
js代码块中 <!-- 被当做 // 处理
g592010667 2015-08-24
  • 打赏
  • 举报
回复
多谢neorobin,我再去找js的书籍看下
g592010667 2015-08-24
  • 打赏
  • 举报
回复
<!-- function reload(){
location.replace("http://baidu.com");
}
//-->
是有这种注释的用法的,现在两个代码的区别是下面代码多个换行符。。。
neorobin 2015-08-24
  • 打赏
  • 举报
回复
<!-- 所在的整行(并且以 <!-- 开头)被浏览器 JS 解析引擎跳过
<html>
<head>
<script type="text/javascript">
alert('this line before HTML comment');<!--
<!-- alert('ignore this line');
alert('this line valid');
-->
</script>
</head>
</html>
marzone 2015-08-24
  • 打赏
  • 举报
回复
你好好查询下js应该如何注释!

87,955

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧