<script type="text/javascript">
/*
* 三个输出语句
*/
alert("This is alert code."); /* 警报框 */
document.write("This is common text."); /*向<body>中输出一个内容*/
console.log("This is log text."); /*向控制台中输出内容*/
</script>
<!-- 将js写在onclick属性中 -->
<!-- 点击后执行onclick后的内容 -->
<button onclick="alert('Botton');">Click this</button>
<!-- Run JavaScript Code When Clicked the Button.>
<!-- Not Common Function. -->
<a herf="javascript:alert('something');">Click This</a>
alert("Something");
在html中引用该代码:
<!-- 引用外部文件 -->
<!-- Whatever it is a file or a link.-->
<script type="text/javascript" src="/path/to/file"></script>
<!-- 'src' replaced the code between two labels.
so system can't run any code written inside if you defined the src.
-->
此方法可以在不同的页面中同时引用,也可以利用到浏览器的缓存机制,推荐。