JavaScript¶¨ÒåÀàµÄ¼¸ÖÖ·½Ê½
ÌáÆðÃæÏò¶ÔÏóÎÒÃǾÍÄÜÏëµ½À࣬¶ÔÏ󣬷â×°£¬¼Ì³Ð£¬¶à̬¡£ÔÚ¡¶javaScript¸ß¼¶³ÌÐòÉè¼Æ¡·£¨ÈËÃñÓʵç³ö°æÉ磬²ÜÁ¦¡¢ÕÅÐÀÒë¡£Ó¢ÎÄÃû×ÖÊÇ£ºProfessional JavaScript for Web Developers£©Õâ±¾ÊéÖÐÃèÊöµÄ»¹Ëã±È½ÏÏêϸ¡£ÎÒÃÇ¿´¿´JavaScriptÖж¨ÒåÀàµÄ¸÷ÖÖ·½·¨¡£
1£®¹¤³§·½Ê½
javaScriptÖд´½¨×Ô¼ºµÄÀàºÍ¶ÔÏó£¬ÎÒÃÇÓ¦¸ÃÊDZØÐëÕÆÎյģ¬ÎÒÃǶ¼ÖªµÀjavaScriptÖжÔÏóµÄÊôÐÔ¿ÉÒÔÔÚ¶ÔÏó´´½¨ºó¶¯Ì¬¶¨Ò壬±ÈÈçÏÂÃæµÄ´úÂ룺
<script type="text/javascript">
//¶¨Òå
var oCar = new Object();
oCar.color = "red";
oCar.doors = 4;
oCar.showColor = function() {
alert(this.color);
}
//µ÷ÓÃ
oCar.showColor();
</script>
ÎÒÃǺÜÈÝÒ×ʹÓÃoCar¶ÔÏ󣬵«ÊÇÎÒÃÇ´´¾ÍÊÇÏë´´½¨¶à¸öCarʵÀý¡£ÎÒÃÇ¿ÉÒÔʹÓÃÒ»¸öº¯ÊýÀ´·â×°ÉÏÃæµÄ´úÂëÀ´ÊµÏÖ£º<script type="text/javascript">
//¶¨Òå
function createCar() {
var oCar = new Object();
oCar.color = "red";
oCar.doors = 4;
oCar.showColor = function() {
alert(this.color);
}
return oCar;
}
//µ÷ÓÃ
var ocar1 = createCar();
var ocar2 = createCar();
ocar1.color = "black";
ocar1.showColor();
ocar2.showColor();
</script>
˳±ã˵һÏ£¬javaScript¶ÔÏóĬÈϳÉÔ±ÊôÐÔ¶¼ÊÇpublic µÄ¡£ÕâÖÖ·½Ê½ÎÒÃdzÆÎª¹¤³§·½Ê½£¬ÎÒÃÇ´´ÔìÁËÄÜ´´½¨²¢·µ»ØÌض¨ÀàÐ͵ĶÔÏóµÄ¹¤³§¡£
ÕâÑù×öÓеãÒâ˼ÁË£¬µ«ÊÇÔÚÃæÏò¶ÔÏóÖÐÎÒÃǾ³£Ê¹Óô´½¨¶ÔÏóµÄ·½·¨ÊÇ£º
Car car=new Car();
ʹÓÃnew ¹Ø¼ü×ÖÒѾÉîÈëÈËÐÄ£
Ïà¹ØÎĵµ£º
<input type=text onkeypress="return event.keyCode>=48&&event.keyCode<=57||(this.value.indexOf('.')<0?event.keyCode==46:false)" onpaste="return !clipboardData.getData('text').match(/\D/)" ondragenter="return false">
<asp:TextBox ID="TextBox1" runat="server" onkeyu ......
1.¶ÔÓÚÊý×飬ÎÒÃÇ¿ÉÒÔ×Ô¼ºÐ´Ò»¸öindexOf()·½·¨:
[].indexOf || (Array.prototype.indexOf = function(v){
for(var i = this.length;i-- && this[i] !== v;);
return i; });
ʹÓ㺠var array = new Array();
array = ...;
if(array.ind ......
EventÊôÐԺͷ½·¨£º
1. type£ºÊ¼þµÄÀàÐÍ£¬ÈçonlickÖеÄclick£»
2. srcElement/target£ºÊ¼þÔ´£¬¾ÍÊÇ·¢ÉúʼþµÄÔªËØ£»
3. button£ºÉùÃ÷±»°´ÏµÄÊó±ê¼ü£¬ÕûÊý£¬1´ú±í×ó¼ü£¬2´ú±íÓÒ¼ü£¬4´ú±íÖмü£¬Èç¹û°´Ï¶à¸ö¼ü£¬¾Æ°ÑÕâЩֵ¼ÓÆðÀ´£¬ËùÒÔ3¾Í´ú±í×óÓÒ¼üͬʱ°´Ï£»£¨firefoxÖÐ 0´ú±í×ó¼ü£¬1´ú±íÖмä¼ü£¬2´ú±íÓÒ¼ü£© ......
¾³£»áÔÚjsÀïÓõ½Êý×é,±ÈÈç ¶à¸öÃû×ÖÏàͬµÄinput, ÈôÊǶ¯Ì¬Éú³ÉµÄ, Ìύʱ¾ÍÐèÒªÅÐ¶ÏÆäÊÇ·ñÊÇÊý×é.
if(document.mylist.length != "undefined" ) {} Õâ¸öÓ÷¨ÓÐÎó.
ÕýÈ·µÄÊÇ if( typeof(document.mylist.length) != "undefined" ) {}
»ò if( !isNaN(document.mylist.length) ) {}
typeof ......