javascript Ç¿ÖÆÀàÐÍת»»
À´Ô´£ºhttp://www.diybl.com/course/1_web/javascript/jsjs/2007114/83289.html
Ç¿ÖÆÀàÐÍת»»
ʹÓÃÇ¿ÖÆÀàÐÍת»»£¨type casting£©´¦Àíת»»ÖµµÄÀàÐÍ¡£Ê¹ÓÃÇ¿ÖÆÀàÐÍת»»¿ÉÒÔ·ÃÎÊÌض¨µÄÖµ£¬¼´Ê¹ËüÊÇÁíÒ»ÖÖÀàÐ͵ġ£JSÖпÉÓõÄ3ÖÖÇ¿ÖÆÀàÐÍת»»ÈçÏ£º
Boolean(value)——°Ñ¸ø¶¨µÄֵת»»³ÉBooleanÐÍ£»
Number(value)——°Ñ¸ø¶¨µÄֵת»»³ÉÊý×Ö£¨¿ÉÒÔÊÇÕûÊý»ò¸¡µãÊý£©£»
String(value)——°Ñ¸ø¶¨µÄֵת»»³É×Ö·û´®¡£
ÓÃÕâÈý¸öº¯Êý֮һת»»Öµ£¬½«´´½¨Ò»¸öÐÂÖµ£¬´æ·ÅÓÉÔʼֱֵ½Óת»»³ÉµÄÖµ¡£Õâ»áÔì³ÉÒâÏë²»µ½µÄºó¹û¡£
µ±Òª×ª»»µÄÖµÊÇÖÁÉÙÓÐÒ»¸ö×Ö·ûµÄ×Ö·û´®¡¢·Ç0Êý×Ö»ò¶ÔÏó£¨ÏÂÒ»½Ú½«ÌÖÂÛÕâÒ»µã£©Ê±£¬Boolean()º¯Êý½«·µ»Øtrue¡£Èç¹û¸ÃÖµÊÇ¿Õ×Ö·û´®¡¢Êý×Ö0¡¢undefined»ònull£¬Ëü½«·µ»Øfalse¡£¿ÉÒÔÓÃÏÂÃæµÄ´úÂë¶Î²âÊÔBooleanÐ͵ÄÇ¿ÖÆÀàÐÍת»»¡£
var b1 = Boolean(“”); //false – empty string
var b2 = Boolean(“hi”); //true – non-empty string
var b3 = Boolean(100); //true – non-zero number
var b4 = Boolean(null); //false - null
var b5 = Boolean(0); //false - zero
var b6 = Boolean(new Object()); //true – object
Number()µÄÇ¿ÖÆÀàÐÍת»»ÓëparseInt()ºÍparseFloat()·½·¨µÄ´¦Àí·½Ê½ÏàËÆ£¬Ö»ÊÇËüת»»µÄÊÇÕû¸öÖµ£¬¶ø²»ÊDz¿·ÖÖµ¡£parseInt()ºÍparseFloat()·½·¨Ö»×ª»»µÚÒ»¸öÎÞЧ×Ö·û֮ǰµÄ×Ö·û´®£¬Òò´Ë"4.5.6"½«±»×ª»»Îª"4.5"¡£ÓÃNumber()½øÐÐÇ¿ÖÆÀàÐÍת»»£¬"4.5.6"½«·µ»ØNaN£¬ÒòΪÕû¸ö×Ö·û´®Öµ²»ÄÜת»»³ÉÊý×Ö¡£Èç¹û×Ö·û´®ÖµÄܱ»ÍêÕûµØת»»£¬Number()½«ÅжÏÊǵ÷ÓÃparseInt()·½·¨»¹Êǵ÷ÓÃparseFloat()·½·¨¡£Ï±í˵Ã÷Á˶Բ»Í¬µÄÖµµ÷ÓÃNumber()·½·¨»á·¢ÉúµÄÇé¿ö£º
Óá¡¡¡·¨½á¡¡¡¡¹û
Number(false) 0
Number(true) 1
Number(undefined) NaN
Number(null) 0
Number("5.5") 5.5
Number("56") 56
Number("5.6.7") NaN
Number(new Object()) NaN
Number(100) 100
×îºóÒ»ÖÖÇ¿ÖÆÀàÐÍת»»·½·¨String()ÊÇ×î¼òµ¥µÄ£¬ÒòΪËü¿É°ÑÈκÎֵת»»³É×Ö·û´®¡£ÒªÖ´ÐÐÕâÖÖÇ¿ÖÆÀàÐÍת»»£¬Ö»ÐèÒªµ÷ÓÃ×÷Ϊ²ÎÊý´«µÝ½øÀ´µÄÖµµÄtoString()·½·¨£¬¼´°Ñ1ת»»³É "1"£¬°Ñtrueת»»³É"true"£¬°Ñfalseת»»³É"false"£¬ÒÀ´ËÀàÍÆ¡£Ç¿ÖÆת»»³É×Ö·û´®ºÍµ÷ÓÃtoString()·½·¨µÄΨһ²»Í¬Ö®´¦ÔÚÓÚ£¬¶Ônull»òunde
Ïà¹ØÎĵµ£º
//µÚÒ»ÖÖ¹¹Ôì·½·¨: new Object()
var a = new Object();
a.x = 1, a.y = 2;
//µÚ¶þÖÖ¹¹Ôì·½·¨: ¶ÔÏóÖ±½ÓÁ¿
var b = {x:1,y:b};
//µÚÈýÖÖ¹¹Ôì·½·¨: ¶¨ÒåÀàÐÍ
function Point(x,y)
{
......
<script language = "JavaScript">
function unicode(s){
var len=s.length;
var rs="";
for(var i=0;i<len;i++){
var k=s.substring(i,i+1);
rs+="&#"+s.charCodeAt(i)+";";
}
return rs;
}
function runicode(s){
var k=s.split(";");
var r="";
for(var x=0;x<k.length;x++){ ......
// ¹Ø±Õ´°¿Úʼþ
function closeWindow(){
if(event.clientX>document.body.clientWidth) {
& ......
/** ÅäÖòÎÊý */
function TreeConfig() {
this.showIco = true;
this.showCheckBox = false;
this.checkBoxName = "_TREE_CHECKBOX_";
this.checkBoxRelated = false;
}
/**
* ½ÚµãÀà
* ½ÚµãĿǰĬÈÏÖ§³ÖµÄÊôÐÔÓ ......