<!DOCTYPE html>
<html>
<head>
<title>ceshi</title>
</head>
<body>
<noscript>
<p>本页面需要浏览器支持(启用)Javascript</p>
</noscript>
<script><!--
alert("Hi");
//--></script>
</body>
</html>
|
禁用当前页面JS后:
<!DOCTYPE> 不是 HTML 标签。它为浏览器提供一项信息(声明),即 HTML 是用什么版本编写的。
JavaScript基本概念
<!DOCTYPE html>
<html>
<head>
<title>For-In Statement Example 1</title>
</head>
<body>
<script type="text/javascript">
for (var propName in window) {
document.write(propName);
document.write("<br />");
}
</script>
</body>
</html>
|
<!DOCTYPE html>
<html>
<head>
<title>Break Statement Example 2</title>
<script type="text/javascript">
var num = 0;
outermost:
for (var i=0; i < 10; i++) {
for (var j=0; j < 10; j++) {
if (i == 5 && j == 5) {
break outermost;
}
num++;
}
}
alert(num);
//55
</script>
</head>
<body>
</body>
</html>
|
<!DOCTYPE html>
<html>
<head>
<title>With Statement Example 1</title>
<script type="text/javascript">
with(location){
var qs = search.substring(1);
var hostName = hostname; //unavailable when viewing from a local file
var url = href;
}
alert(qs);
alert(hostName);
alert(url);
</script>
</head>
<body>
</body>
</html>
|
<script type="text/javascript">
function doAdd(num1, num2) {
if(arguments.length == 1) {
alert(num1 + 10);
} else if (arguments.length == 2) {
alert(arguments[0] + num2);
}
}
doAdd(10); //20
doAdd(30, 20); //50
</script>
|
<script type="text/javascript">
function doAdd(num1, num2) {
arguments[1] = 10;
alert(arguments[0] + num2);
}
doAdd(10, 20); //20
doAdd(30, 20); //40
</script>
|
<script type="text/javascript">
function addSomeNumber(num){
return num + 100;
}
function addSomeNumber(num) {
return num + 200;
}
var result = addSomeNumber(100); //300
alert(result);
</script>
|