菜鸟学习javascript实例教程
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
菜鸟学习javascript实例教程
用JS显示文字的例子:
用HTML标签来格式化文本的例子:
书写JS位置的例子:
打开页面弹出窗口的例子
function message()
{
alert("网页教学网欢迎你的光临")
}
在BODY区内输出显示文本的例子:
document.write("欢迎光临网页教学网")
调用其它的一个JS文件的例子:
The actual script is in an external script file called "xxx.js".
变量的使用
变量使用的例子:
var name = "Hege"
document.write(name)
document.write("
"+name+"
")This example declares a variable, assigns a value to it, and then displays the variable.
Then the variable is displayed one more time, only this time as a heading.
函数的例子
函数使用的一个例子:
function myfunction()
{
alert("HELLO")
}
By pressing the button, a function will be called. The function will alert a message.
带一个参数的函数的例子:
function myfunction(txt)
{
alert(txt)
}
By pressing the button, a function with an argument will be called. The function will alert
this argument.
不同的两个参数调用函数的例子:
function myfunction(txt)
{
alert(txt)
}