日期:2014-05-16  浏览次数:20339 次

javascript复习1:基础
	<input type="button" onclick="disp_alert()" value="显示警告框" /><br />
	<input type="button" value="View message" onclick="message()" /><br />
	<input type="button" value="th" onclick="th()" /><br />
	function disp_alert()
	{
	alert("再次向您问好!在这里,我们向您演示" + '\n' + "如何向警告框添加折行。")
	}
		var i=0
		for (i=0;i<=6;i++)
		{
		if (i==3){continue}
		document.write("The number is " + i)
		document.write("<br />")
		}
		var x
		var mycars = new Array()
		mycars[0] = "Saab"
		mycars[1] = "Volvo"
		mycars[2] = "BMW"
		
		for (x in mycars)
		{
		document.write(mycars[x] + "<br />")
		}
		var txt=""
		function message()
		{
		try
		  {
		  adddlert("Welcome guest!")
		  }
		catch(err)
		  {
		  txt="此页面存在一个错误。\n\n"
		  txt+="错误描述: " + err.description + "\n\n"
		  txt+="点击OK继续。\n\n"
		  alert(txt)
		  }
		}
		function th()
		{
			var x=prompt("Enter a number between 0 and 10:","")
			try
			{ 
			if(x>10) 
			throw "Err1"
			else if(x<3)
			throw "Err2"
			} 
			catch(er)
			{
			if(er=="Err1") 
			alert("Error! The value is too high")
			if(er == "Err2") 
			alert("Error! The value is too low") 
			}
		}