document.write("积木网www.gimoo.net"); 2.页面内

编程语言


javascript基础第一章 JavaScript与用户端

网络编程 javascript基础第一章 JavaScript与用户端 06-22
一 页面输出
1.头部文件

<head>
<script language="javascript">
document.write("积木网www.gimoo.net");
</script>
</head>

2.页面内

<body>
<script>
document.write("积木网");
</script>
</body>

3.外部文件
<script src="display.js"></script>
4.利用页面ID的innerHtml

<script>
window.onload = writeMessage; // 页面加载时调用writeMessage函数
writeMessage() {
document.getElementById("helloMessage").innerHTML = "积木网";
//找到dom ID(helloMessage),修改其html内容
}
</script>

5.警告
alert("广州百汇物流有限公司");
6.询问

if (confirm("是否访问我们的首页"))
{
alert("是的,前往");
}
else {
alert("退出");
}

7.输入

var ans = prompt("输入你的留言","您好,");
if (ans) {
alert("你说:" + ans);
}
else {
alert("退出,没有留言");
}

8.页面跳转

<script>
window.onload = initAll;
function initAll() {
document.getElementById("redirect").onclick = initRedirect;
}
function initRedirect()
{
window.location = "index.html";
return false;
}
</script>
<a href="http://www.gimoo.net" id="redirect">积木网</a>

9.判断分支

<script>
window.onload = initAll;
function initAll() {
document.getElementById("Lincoln").onclick = saySomething;
document.getElementById("Kennedy").onclick = saySomething;
document.getElementById("Nixon").onclick = saySomething;
}
function saySomething() {
switch(this.id) {
case "Lincoln":
alert("Four score and seven years ago...");
break;
case "Kennedy":
alert("Ask not what your country can do for you...");
break;
case "Nixon":
alert("I am not a crook!");
break;
default:
}
}
</script>
<form action="#">
<input type="button" id="Lincoln" value="Lincoln" />
<input
type="button" id="Kennedy" value="Kennedy" />
<input type="button" id="Nixon"
value="Nixon" />
</form>

10.异常捕获

window.onload = initAll;
function initAll() {
var ans = prompt("输入参数:","");
try {
if (!ans || isNaN(ans) || ans<0) {
throw new Error("输入为非数");
}
alert("根号" + ans + " 是 " + Math.sqrt(ans));
}
catch (errMsg) {
alert(errMsg.message);
}
}

javascript函数中的arguments参数
中午的时候稍微研究了下javascriptfunction中的argumentsscripttype="text/javascript"window.onload=function(){(function(arg1,arg2){alert(arguments.length);alert(arguments.callee.length);})();

JavaScript 键盘event.keyCode值列表大全
网上收集的KeyCode值方便大家查找:keycode8=BackSpaceBackSpacekeycode9=TabTabkeycode12=Clearkeycode13=Enterkeycode16=Shift_Lkeycode17=Control_Lkeycode18=Alt_Lkeycode19=Pausekeycode20=Caps_L

JavaScript中关于indexOf的使用方法与问题小结
这个方法相当有用,很多编程语言中都有相对应的实现,javascript中也不例外,然而当我在ie中运行如下代码时候:vararr=[1,2,3];alert(arr.indexOf(1));却被提示


编辑:编程语言

标签:积木,页面,函数,时调,根号