JavaScript³õѧÕßӦעÒâµÄÆ߸öϸ½Ú
£¨1£©¼ò»¯´úÂë
JavaScript¶¨Òå¶ÔÏóºÍÊý×é·Ç³£¼òµ¥£¬ÎÒÃÇÏëÒª´´½¨Ò»¸ö¶ÔÏó£¬Ò»°ãÊÇÕâÑùдµÄ£º
var car = new Object();
car.colour = 'red';
car.wheels = 4;
car.hubcaps = 'spinning';
car.age = 4;
ÏÂÃæµÄд·¨¿ÉÒԴﵽͬÑùµÄЧ¹û£º
var car = {
colour:'red',
wheels:4,
¡¡¡¡hubcaps:'spinning',
¡¡¡¡age:4
}
ºóÃæµÄд·¨Òª¶ÌµÃ¶à£¬¶øÇÒÄã²»ÐèÒªÖظ´Ð´¶ÔÏóÃû³Æ¡£
ÁíÍâ¶ÔÓÚÊý×éͬÑùÓмò½àµÄд·¨£¬¹ýÈ¥ÎÒÃÇÉùÃ÷Êý×éÊÇÕâÑùдµÄ£º
var moviesThatNeedBetterWriters = new Array(
'Transformers','Transformers2','Avatar','Indiana Jones 4'
);
¸ü¼ò½àµÄд·¨ÊÇ£º
var moviesThatNeedBetterWriters = [
'Transformers','Transformers2','Avatar','Indiana Jones 4'
];
¶ÔÓÚÊý×飬»¹ÓйØÁªÊý×éÕâÑùÒ»¸öÌرðµÄ¶«Î÷¡£ Äã»á·¢Ïֺܶà´úÂëÊÇÕâÑù¶¨Òå¶ÔÏóµÄ£º
var car = new Array();
car['colour'] = 'red';
car['wheels'] = 4;
car['hubcaps'] = 'spinning';
car['age'] = 4;
ÕâÌ«·è¿ñÁË£¬²»Òª¾õµÃÀ§»ó£¬¡°¹ØÁªÊý×顱ֻÊǶÔÏóµÄÒ»¸ö±ðÃû¶øÒÑ¡£
ÁíÍâÒ»¸ö¼ò»¯´úÂëµÄ·½·¨ÊÇʹÓÃÈýÔªÔËËã·û£¬¾Ù¸öÀý×Ó£º
var direction;
if(x < 200){
direction = 1;
} else {
direction = -1;
}
ÎÒÃÇ¿ÉÒÔʹÓÃÈçϵĴúÂëÌæ»»ÕâÖÖд·¨£º
var direction = x < 200 ? 1 : -1;
£¨2£©Ê¹ÓÃJSON×÷ΪÊý¾Ý¸ñʽ
ΰ´óµÄDouglas Crockford·¢Ã÷ÁËJSONÊý¾Ý¸ñʽÀ´´æ´¢Êý¾Ý£¬Äã¿ÉÒÔʹÓÃÔÉúµÄjavascript·½·¨À´´æ´¢¸´ÔÓµÄÊý¾Ý¶ø²»ÐèÒª½øÐÐÈκζîÍâµÄת»»£¬ÀýÈ磺
var band = {
"name":"The Red Hot Chili Peppers",
"members":[
{
"name":"Anthony Kiedis",
"role":"lead vocals"
},
{
"name":"Michael 'Flea' Balzary",
"role":"bass guitar, trumpet, backing vocals"
},
{
"name":"Chad Smith",
"role":"drums,percussion"
},
{
"name":"John Frusciante",
"role":"Lead Guitar"
}
],
"year":"2009"
}
Äã¿ÉÒÔʹÓÃÔÚJavaScriptÖÐÖ±½ÓʹÓÃJSON£¬ÉõÖÁ×÷ΪAPI·µ»ØµÄÒ»ÖÖ¸ñʽ£¬Õâ¾ÍÊÇËùνµÄJSON ¨C P£¬ÔÚÐí¶àµÄAPIÖб»Ó¦Óã¬ÀýÈ磺
ÕâÀïµ÷ÓÃdelicious µÄWeb·þÎñ»ñÈ¡×îÐÂÊéÇ©£¬ÒÔJSON¸ñʽ·µ»Ø£¬È»ºó½«ËüÃÇÏÔʾ³ÉÎÞÐòÁбíµÄÐÎʽ¡£
´Ó±¾ÖÊÉϽ²£¬JSONÊÇÓÃÓÚÃèÊö¸´ÔÓµÄÊý¾Ý×îÇáÁ¿¼¶µÄ·½Ê½£¬¶øÇÒÖ±½ÓËüÔËÐÐÔÚä¯ÀÀÆ÷ÖС£ ÄãÉõÖÁ¿ÉÒÔÔÚPHPÖе÷Óà json_decode£¨£©º¯ÊýÀ´Ê¹ÓÃËü¡£
£¨3£©¾¡Á¿Ê¹ÓÃJavaScriptÔÉúº¯Êý
ÒªÕÒÒ»×éÊý×ÖÖеÄ×î´óÊý£¬ÎÒÃÇ¿ÉÄÜ»áдһ¸öÑ»·£¬ÀýÈ磺
var numbers = [3,342,23,22,124];
var max = 0;
for(var i=0;i
Æäʵ£¬²»ÓÃÑ»·¿ÉÒÔʵÏÖͬÑùµÄ¹¦ÄÜ£º
var numbers = [3,342,23,22,124];
numbers.sort(function(a,b){return b - a});
alert(numbers[0]);
¶ø×î¼ò½àµÄд·¨ÊÇ£º
Math.max(12,123,3,2,433,4); // returns 433
ÄãÉõÖÁ¿ÉÒÔʹÓÃMath.maxÀ´¼ì²âä¯ÀÀÆ÷Ö§³ÖÄĸöÊôÐÔ£º
var scrollTop= Math.max(
doc.documentElement.scrollTop,
doc.body.scrollTop
);
Èç¹ûÄãÏë¸øÒ»¸öÔªËØÔö¼ÓclassÑùʽ£¬¿ÉÄÜÔʼµÄд·¨ÊÇÕâÑùµÄ£º
function addclass(elm,newclass){
var c = elm.className;
elm.className = (c === '') ? newclass : c+' '+newclass;
¶ø¸üÓÅÑŵÄд·¨ÊÇ£º
function addclass(elm,newclass){
var classes = elm.className.split(' ');
classes.push(newclass);
elm.className = classes.join(' ');
}
ÍƼöÐÅÏ¢
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- jQuery Tooltips²å¼þ
- jQueryµÄ.bind()¡¢.live()ºÍ.delegate(....
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- Ä㲻ϲ»¶»ðºü£¬µ«ÓÖϲ»¶firebug£¬ÄǾ͸úÎÒÒ»ÆðÀ´ÔÚIEÉÏ....
- ¸ù¾ÝÏÔʾÆ÷·Ö±æÂʵ÷ÕûÒ³ÃæÏÔʾµÄJavascript½Å±¾
- jQuery дµÄ·ÂÐÂÀË΢²© ÏòϹö¶¯Ð§¹û¡¾×ªÔØ¡¿
- ͨÓõÄJqueryÑ¡ÔñÆ÷
- jQuery ½áºÏ Json Ìá½»Êý¾Ýµ½Webservice£¬....
- ×ÔÖÆjQueryÖÇÄÜÌáʾ²å¼þһö
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- js»ñÈ¡srcÖд«µÝµÄ²ÎÊý
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- ÈÃä¯ÀÀÆ÷ÆÁ±ÎµôJavaScriptµÄ³ö´íÌáʾ
- github²»ÄܼÓÔØcss¡¢js½â¾ö°ì·¨
- ÎÒÖªµÀµÄJavaScript -- Éè¼Æģʽ(ÇŽÓ)Ó¦ÓÃÖ® ¨C ....
- 15¸öÖµµÃ¿ª·¢ÈËÔ±¹Ø×¢µÄjQuery¿ª·¢¼¼ÇɺÍÐĵÃ
- dz̸JavascriptÃæÏò¶ÔÏó±à³Ì
- JS¼òµ¥¶¯»·â×°
- JavaScript³õѧÕßӦעÒâµÄÆ߸öϸ½Ú
- jQuery Tooltips²å¼þ
ÆÀÂÛ