javascript代码没有显示我预期的输出

时间:2012-03-17 11:40:10

标签: javascript notepad++

我正在nodepad ++上编写javascript代码,我在初学者级别并且只编写此代码

<html>
<body>
<script type="text/javascript">
var d=new Date();
var time=d.getHours();
if(time<10)
{
document.write("<b> good morning </b>");

}
else
{
document.write ("<b> good afternoon </b>");

}
</script>
</body>
</html>

然后从编辑器nodepad ++,我点击在谷歌浏览器中运行,但只得到了这个

<html>
<body>
<script type="text/javascript">
var d=new Date();
var time=d.getHours();
if(time<10)
{
document.write("<b> good morning </b>");

}
else
{
document.write ("<b> good afternoon </b>");

}
</script>
</body>
</html>

代码的副本而不是结果,为什么?

2 个答案:

答案 0 :(得分:4)

我认为您将文件保存为txt而不是html。然后浏览器只会显示内容而不会呈现代码。

将其另存为HTML文件,您的问题应该得到解决。

答案 1 :(得分:2)

将您的文件保存为.html而不是.js,并在浏览器中打开它是内联的JavaScript! 它应该工作

相关问题