点击访问我的网站,查看效果 上海驾校 js:嵌入在html中,处理数据,其实和as差不多,个人理解是html展示界面,js处理数据 嵌入在html中使用script document.write 用于像页面输出语句 <html> <head> <body> <script type="text/javascript"> document.write("hello world"); </script> </body> </head> </html> 生成普通文件和标签 <html> <script type="text/javascript"> document.write("<h>hello world</h>"); </script> <body> </body> </html> 也可嵌入在head中 onload 事件会在页面或图像加载完成后立即发生。 <html> <head> <script type="text/javascript"> function message(){ alert("该提示框通过onload事件调用的") } </script> <body onload="message()"> </body> </head> </html> 定义外部脚本 src= "根目录文件" <html> <head> </head> <body> <script src="/ceshi.js"> </script> <p> 实际是外部的jacascript文件 ceshi.js </p> </body> </html> 完整的javascript语句 <html> <body> <script type="text/javascript"> document.write("<h1>hello world</h1>"); document.write("<p>hello world</p>"); </script> </body> </html> javascript 代码块 <script type="text/javascript"> { document.write("<h1>hello world</h1>"); document.write("<p>hello world</p>"); } </script> javascript 代码注释 <html> <body> <script type="text/javascript"> //这行是注释 document.write("<h1>hello world</h1>"); /*这行是多行注释 jjjj看看*/ document.write("<p>hello world</p>"); </script> </body> </html> 声明一个变量,为其赋值,显示.<br />换行.定义是用var <html> <body> <script type="text/javascript"> var firstName; firstName = "George"; document.write(firstName); document.write("<br />"); firstName = "John"; document.write(firstName); </script> <p>上面的脚本声明了一个变量,为其赋值,显示该值,改变该值,然后再显示该值。</p> </body> </