专栏首页闵开慧javascript入门操作

javascript入门操作

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <script type="text/javascript">
	function disp_alert(){
		alert("Äãµã»÷Á˾¯¸æ¿ò£¡");
	}
	function onmouseoverTest(){
		alert("Welcome!");
		//document.write("welcome!");
	}
	function disp_confirm(){
		var con=confirm("Are you sure?");
		if(con)
			//alert("You select sure!");
			document.write("Welcome!");
		else
			alert("You select cancel!");
	}
	function disp_prompt(){
		var name=prompt("ÇëÊäÈëÄãµÄÃû×Ö");
		if(name!=null&&name!=""){
			document.write("Hello,"+name+"!");
		}else{
			alert("ÇëÊäÈëÐÕÃû£¡");
		}
	}
	function product(a,b){
		return(a*b);
	}
	function message(){
		try{
			addalert("Welcome guest!");
		}catch(err){
			txt="¸ÃÍøÒ³ÓдíÎó£¡\nµã»÷È·¶¨¼ÌÐø²é¿´±¾Ò³¡£\nµã»÷È¡Ïû·µ»ØÖ÷Ò³¡£";
			if(!confirm(txt)){
				document.location.href="http://www.7789.com";
			}
		}
	}
	function judge(){
		var number=prompt("Input a number from 0 to 10:","");
		try{
			if(number<0){
				throw "small";
			}else if(number>=0&&number<=10){
				alert("You are right!");
			}else{
				throw "large";
			}
		}catch(err){
			if(err=="small")
				alert("The input is smaller!");
			else if(err=="large")
				alert("The input is larger!");
		}
	}
	function checkTime(i){
		if(i<10){
			i="0"+i;
		}
		return i;
	}
	function startTime(){
		var today=new Date();
		var h=today.getHours();
		var m=today.getMinutes();
		var s=today.getSeconds();
		m=checkTime(m);
		s=checkTime(s);
		document.getElementById("txt").innerHTML=h+":"+m+":"+s;
		t=setTimeout("startTime()",500);
	}
	function getValue(){
		var x=document.getElementById("myHeader");
		alert(x);
		alert(x.innerHTML);//×¢ÒâÆäÖеÄinnerHTMLµÄÊéд£¬·ñÔò»á³ö´íÎó¡£
	}
	function getElements(){
		var x=document.getElementsByName("input");
		alert(x);
		alert(x.length);
		alert(x.innerHTML);
	}
	function getElementsByTagNameTest(){
		var x=document.getElementsByTagName("input");
		alert(x.length);
	}
	function validate_required(field,alertTxt){
		with(field){
			if(value==null||value==""){
				alert(alertTxt);
				return false;
			}else{
				return true;
			}
		}
	}
	function validate_email(field,alertTxt){
		with(field){
			apos=value.indexOf("@");
			dotpos=value.lastIndexOf(".");
			if(apos<1||(dotapos-apos)<2){
				alert(alertTxt);
				return false;
			}else{
				return true;
			}
		}
	}
	function validate_form(thisForm){
		with(thisForm){
			if(validate_required(email,"Email must be filled out!")==false){
				email.focus();
				return false;
			}
			if(validate_email(email,"Not a validatde email address!")==false){
				email.focus();
                return false;
			}
		}
	}
  </script>
 </head>

 <body onload="startTime()">
	<script type="text/javascript">
		document.write("Hello World!");
		var x=5+5;
		document.write("<br/>"+x);
		var x=5+"5";
		document.write("<br>"+x);
		var x="5"+5;
		document.write("<br>"+x);
		var x="5"+"5";
		document.write("<br>"+x);
		var x=5;
		document.write("<br>"+(x==="5"));//×¢ÒâÒª¼Ó()£¬·ñÔò²»°´¹æÔòÀ´
		document.write("<br>"+x);
		document.write("<br>"+(x===5));//×¢ÒâÒª¼Ó()£¬·ñÔò²»°´¹æÔòÀ´£¬´ð°¸Îªfalse

		var x=10;
		var result=(x>9)?"Too young!":"Too old!";
		document.write("<br>"+result+"<br>");

		switch(x){
			case 11:
				document.write("10");
				break;
			case 15:
				document.write("15");
				break;
			case 6:
				document.write("6");
				break;
			case 0:
				document.write("0");
				break;
			default:
				document.write("Nothing");
		}

		document.write("<br>2*3="+product(2,3)+"<br>");

		for(i=0;i<10;i++){
			document.write("<h"+i+">±êÌâ"+i+"</h"+i+"><br>");
		}

		var array=new Array("1","2","3","4","5");
		for(x in array){
			document.write(array[x]+"<br>");
		}

		var txt="Hello,\"John\",sdfgdf";
		document.write(txt);
		document.write("<br>You \& me are singing!");
		document.write("<br>Hello \
		everyone!<br>");

		//¶ÔÏó
		var str="Hello world!";
		document.write(str.length+"<br>");//ÕâÀïµÄµ¥´ÊÊý²»°üÀ¨¿Õ¸ñ
		document.write(str.toUpperCase()+"<br>");
		document.write(str.toLowerCase()+"<br>");
		document.write(str.replace("!","!!!"));
		//ʱ¼ä
		document.write(Date());
		//Êý×é
		var array1=new Array("0","1","2","3","4","5");
		var array2=new Array("h","f","a","b","c","d","e");
		document.write("<br>"+array1);
		document.write("<br>"+array1.concat(array2));
		document.write("<br>"+array1);
		document.write("<br>"+array1.join("."));
		document.write("<br>"+array2.sort());

		//boolean
		var b=new Boolean();//×¢ÒâÇ°ÃæµÄÉùÃ÷Ϊvar£¬¶ø²»ÊÇBoolean¡£
		document.write(b);
		var b=new Boolean(0);
		document.write(b);
		var b=new Boolean(false);
		document.write(b);
		var b=new Boolean(true);
		document.write(b);
		var b=new Boolean("false");
		document.write(b);

		//math
		document.write("<br>"+Math.random());
		document.write("<br>"+Math.round(5.2));
		document.write("<br>"+Math.floor(Math.random()*12));
		
		//ÕýÔò±í´ïʽ
		re=new RegExp("ex");
		document.write("<br>"+re.test("Hello every one!"));
		document.write("<br>"+re.test("expression"));
		document.write("<br>"+re.exec("Hello world! expression"));
		re=new RegExp("e","g");
		do{
		    result=re.exec("The best thing in the life is free!");
			document.write(result);
		}while(result!=null)

		var re=new RegExp("e");
		document.write(re.exec("The best thing in the life is free!"));
		re.compile("g");
		document.write(re.test("The best thing in the life is free!"));
		
		document.writeln("<br>"+document.referrer);
		document.writeln("<br>"+navigator.cupClass);
		document.writeln("<br>"+location.port);
		
	</script>
	<div id="txt"></div>
	<br/>
	<input type="button" onclick="disp_alert()" value="¾¯¸æ¿ò"/><br/>
	<input type="text" onmouseover="onmouseoverTest()"/><br/>
	<p onmouseover="onmouseoverTest()">½«Êó±ê·ÅÉÏÀ´ÊÔһϣ¡</p><br/>
	<a href="" onmouseover="onmouseoverTest()">½«Êó±ê·ÅÉÏÀ´ÊÔһϣ¡</a><br/>
	<input type="button" onclick="disp_confirm()" value="½øÈë"/><br/>
	<input type="button" onclick="disp_prompt()" value="×¢²á"/><br/>
	<a href="http://www.7789.com"><img src="logo.jpg"/></a><br/>
	<a href="http://www.7789.com" onmouseover="onmouseoverTest()"><img src="logo.jpg"/></a><br/>
	<input type="button" onclick="message()" value="Ñ¡Ôñ"/><br/>
	<input type="button" onclick="judge()" value="ÅжÏ"/><br/>
	<p id="txt"></p>
	<h1 id="myHeader" onclick="getValue()">±êÌâ1</h1>
	<input type="text" name="input"/>
	<input type="text" name="input"/>
	<input type="text" name="input"/>
	<input type="button" onclick="getElements()" value="getElementsByName"/>
	<input type="button" onclick="getElementsByTagNameTest()" value="getElementsByTagName"/>
	<form action="email.php" onsubmit="return validate_form(this)" method="post">
		Email:<input type="text" name="email" size="30"/>
		<input type="submit" value="submit"/>
	</form>
 </body>
</html>

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • php连接mysql数据库

    <?php /**  * @author minguanghui  * @copyright 2012  */ //Ê...

    闵开慧
  • django中系统时间设置

    打开settings.py,找到如下内容 # Local time zone for this installation. Choices can be fou...

    闵开慧
  • php中时区设置(不设置则时间显示出错)

    具体设置方法: 在php.ini中设置date.timezone的值为PRC,设置好以后的为:date.timezone=PRC,同时取消这一行代码的...

    闵开慧
  • JavaScript|数据类型的使用

    每一种计算机语言都有自己的数据结构和数据类型,JavaScript脚本语言中则是采用弱数据类型的方式,即一个数据不必首先做声明,可以在使用或赋值时再确定其数据的...

    算法与编程之美
  • Javascript设置广告和时间表和数组的学习

    1 <html> 2 <head> 3 <meta charset="utf-8"> 4 <title></title> 5 </hea...

    别先生
  • 什么是龙链?

    你不会想到迪斯尼加入加密货币狂潮,但这正是发生的事情。以Aladdin, The Lion King和最近的Moana等经典动画电影而闻名的心爱的大众传媒和娱乐...

    lemon2ml
  • WordPress _v4.6远程代码执行漏洞复现

    reborn WordPress _v4.6远程代码执行漏洞是PHPMailer漏洞(CVE-2016-10033)在WordPress Core代码的体现,...

    漏斗社区
  • [答疑]自反关联和自连接的区别

    本来不应该回答这个不该成为问题的问题。因为你这样问表明不只是不了解自反关联,可能也对自连接有误解,应该再去学习和复习基本知识才对。不过,这个问题背后也反映了一些...

    用户6288414
  • 嘿,程序员!手把手教你写出智能合约Hello, World

    区块链大本营
  • 智能合约开发

    以太坊平台对底层区块链技术进行了封装,让区块链应用开发者可以直接基于其进行开发,开发者只要专注于应用本身的开发,从而大大降低了难度。 以太坊则是“图灵完备的”,...

    春哥大魔王

扫码关注云+社区

领取腾讯云代金券