HTML5ÈëÃÅ

СǿµÄHTML5Òƶ¯¿ª·¢Ö®Â·£¨27£©¡ª¡ª JavaScript»Ø¹Ë2

×ÖºÅ+ ×÷ÕߣºË®º® À´Ô´£ºcsdn 2015-06-02 14:36 ÎÒÒªÆÀÂÛ( )

JavascriptÃæÏò¶ÔÏó»ù´¡ÖªÊ¶1¡¢ÈçºÎ¶¨ÒåÒ»¸öÀ࣬ʹÓÃÈçÏÂÓï·¨À´´´½¨Ò»¸öÀà function Person(name, age){ //Ï°¹ßÉϵÚÒ»¸ö×Öĸ´óд//thisÐÞÊεıäÁ¿³ÆΪÊôÐÔthis.name = name;this.age = age;//Èç¹ûÊôÐÔÖµÊÇÒ»¸öº¯Êý£¬ÔòÕâ¸öÊôÐÔ¾ÍÊÇÒ»¸ö·½·¨this.play = functi

JavascriptÃæÏò¶ÔÏó»ù´¡ÖªÊ¶

1¡¢ÈçºÎ¶¨ÒåÒ»¸öÀ࣬ʹÓÃÈçÏÂÓï·¨À´´´½¨Ò»¸öÀà

 

	  	function Person(name, age){ //Ï°¹ßÉϵÚÒ»¸ö×Öĸ´óд
			//thisÐÞÊεıäÁ¿³ÆΪÊôÐÔ
			this.name = name;
			this.age = age;
			//Èç¹ûÊôÐÔÖµÊÇÒ»¸öº¯Êý£¬ÔòÕâ¸öÊôÐÔ¾ÍÊÇÒ»¸ö·½·¨
			this.play = function(){
				alert('play football...');
			};
		}
2¡¢ÈçºÎ´´½¨¸ÃÀàµÄʵÀý

 

		var p = new Person('zs', 22);
		p.play();
		p.name;
3¡¢´´½¨javascript¶ÔÏóµÄÁíÍâÁ½ÖÖ·½Ê½

(1)ÏÈ´´½¨Ò»¸öObjectÀàÐ͵ÄʵÀý£¬È»ºóÔö¼ÓеÄÊôÐԺͷ½·¨

javascriptÊÇÒ»ÖÖ¶¯Ì¬ÓïÑÔ£¬¿ÉÒÔÔÚÔËÐÐʱΪ¶ÔÏóÔö¼ÓеÄÊôÐԺͷ½·¨

			var obj = new Object();
			obj.name = 'zs';
			obj.age = 22;
			obj.play = function(){
				alert('play...');
			};
(2)ʹÓÓjson”Óï·¨

 

		  	var p = {'name':'zs','age':22};
			var p = {'name':'zs','play':function(){
				alert('hello');
			}};
»òÕß

 

			var p = {name:'zs',age:22,marrid:false};
			var p = {name:'zs',play:function(){
				alert('hello');
			}};
ÊôÐÔÖµÈç¹ûÊÇ×Ö·û´®±ØÐëÓÃÒýºÅÀ¨ÆðÀ´(µ¥Ë«)

 

ÊôÐÔÖµÔÊÐínumber,string,boolean,null,Object

			var p = {name:'zs',
				address:{
					city:'beijing',
					street:'ca'
				}
			};
Ò»¸öÍêÕûµÄÀý×Ó

 

<html>
	<head>
		<script>
			function f1(){
				//var p = {'name':'zs','age':22};
				//var p = {name:'zs',age:22,marrid:false};
				var p = {name:'zs',
					address:{
						city:'beijing',
						street:'ca'
					}
				};
				//alert(p.name);
				alert(p.address.city);
			}
			function f2(){
				var arr = [
					{'name':'zs','age':22},
					{'name':'ls','age':32}
				];
				alert(arr[1].name);
			}
		</script>
	</head>
	<body>
		<input type="button" value="click me" onclick="f2();"/>
	</body>
</html> 

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • HTML5³£ÓñêÇ©×ܽá

    HTML5³£ÓñêÇ©×ܽá

    2016-03-23 14:02

  • html5ѧµÃºÃ²»ºÃ£¬¿´ÕÆÎÕ¶àÉÙ±êÇ©

    html5ѧµÃºÃ²»ºÃ£¬¿´ÕÆÎÕ¶àÉÙ±êÇ©

    2015-09-28 12:53

  • СǿµÄHTML5Òƶ¯¿ª·¢Ö®Â·£¨53£©¡ª¡ªjQueryMobileÒ³Ãæ¼ä²ÎÊý´«µÝ

    СǿµÄHTML5Òƶ¯¿ª·¢Ö®Â·£¨53£©¡ª¡ªjQueryMobileÒ³Ãæ¼ä²ÎÊý´«µÝ

    2015-06-02 14:32

  • СǿµÄHTML5Òƶ¯¿ª·¢Ö®Â·£¨52£©¡ª¡ªjquerymobileÖеĴ¥¿Ø½»»¥

    СǿµÄHTML5Òƶ¯¿ª·¢Ö®Â·£¨52£©¡ª¡ªjquerymobileÖеĴ¥¿Ø½»»¥

    2015-06-02 14:34

ÍøÓѵãÆÀ
ã