调用外部脚本文件
HTML部分(假设htm文件和js文件在同一个目录下面)
无刷新选择
对象的使用
document.write("custom_car.seats:"+custom_car.seats);
document.write("custom_car.engine:"+custom_car.engine);
document.write("custom_car.theradio:"+custom_car.theradio);
<html>
<HEAD>
<SCRIPT language="Javascript" src="03_src.js" ></SCRIPT>
</HEAD>
<BODY>
<A HREF="javascript:display_quote2()">Click Here, I dare you!</A>
</BODY>
</html>
03_src.js javascript部分<HEAD>
<SCRIPT language="Javascript" src="03_src.js" ></SCRIPT>
</HEAD>
<BODY>
<A HREF="javascript:display_quote2()">Click Here, I dare you!</A>
</BODY>
</html>
function display_quote2()
{
var quote= new Array(5);
var y=0;
for (y=0; y<5; y++)
{
quote[y]=prompt('Enter a Quote!',' ');
}
var x=0;
for (x=0; x<5; x++)
{
alert(quote[x]);
}
}
{
var quote= new Array(5);
var y=0;
for (y=0; y<5; y++)
{
quote[y]=prompt('Enter a Quote!',' ');
}
var x=0;
for (x=0; x<5; x++)
{
alert(quote[x]);
}
}
无刷新选择
<html>
<head>
</head>
<script>
function go(obj){
<!--
var a1=document.getElementById("a1");
alert(a1.href);
-->
a1.href=obj.value;
alert(a1.href);
}
</script>
<body >
<a href="*.html" id="a1">click me</a>
<br/>
<select onchange="go(this)">
<option value="www.baidu.com">百度</option>
<option value="www.google.com">谷歌 </option>
</select>
</body>
</html>
<head>
</head>
<script>
function go(obj){
<!--
var a1=document.getElementById("a1");
alert(a1.href);
-->
a1.href=obj.value;
alert(a1.href);
}
</script>
<body >
<a href="*.html" id="a1">click me</a>
<br/>
<select onchange="go(this)">
<option value="www.baidu.com">百度</option>
<option value="www.google.com">谷歌 </option>
</select>
</body>
</html>
对象的使用
/*javascript 对象*/
function car(seats,engine,theradio)
{
this.seats=seats;
this.engine=engine;
this.theradio=theradio;
}
var work_car=new car("cloth","V-6","Tape Deck");
var fun_car=new car("leather","V-8","CD Player");
var custom_car=new car(fun_car.seats,work_car.engine,"jhtchina");
function car(seats,engine,theradio)
{
this.seats=seats;
this.engine=engine;
this.theradio=theradio;
}
var work_car=new car("cloth","V-6","Tape Deck");
var fun_car=new car("leather","V-8","CD Player");
var custom_car=new car(fun_car.seats,work_car.engine,"jhtchina");
document.write("custom_car.seats:"+custom_car.seats);
document.write("custom_car.engine:"+custom_car.engine);
document.write("custom_car.theradio:"+custom_car.theradio);