代碼使用方法:
0001:
判斷一個(gè)計(jì)算結(jié)果是不是無(wú)窮大:if(isFinite(999999999*999999999) == true)
----------------------------------------------------------------------------------------------------
0002:
判斷是不是數(shù)字:if(isNaN("Blue") == true),不是數(shù)字則為true,是數(shù)字則為false。
----------------------------------------------------------------------------------------------------
0003:
數(shù)字的進(jìn)制轉(zhuǎn)換:
var num = 10;
alert(num.toString()) + "<br>";//十進(jìn)制
alert(num.toString(2)) + "<br>";//二進(jìn)制
alert(num.toString(8)) + "<br>";//八進(jìn)制
alert(num.toString(16)) + "<br>";//十六進(jìn)制
----------------------------------------------------------------------------------------------------
0004:
將字符串類型轉(zhuǎn)換為數(shù)字類型:注意,parseFloat沒(méi)有進(jìn)制參數(shù)可以選擇,都當(dāng)作十進(jìn)制處理
var str = "10";
alert(parseInt(str,10));//字符串被當(dāng)作十進(jìn)制處理
alert(parseInt(str,2));//字符串被當(dāng)作二進(jìn)制處理
----------------------------------------------------------------------------------------------------
0005:
強(qiáng)制類型轉(zhuǎn)換:
var str = "10";
var num = new Number(str);
----------------------------------------------------------------------------------------------------
0006:
Object類的基本屬性和方法:所有類都繼承自O(shè)bject,因此都有這些屬性和方法。
屬性:
●Constructor:對(duì)創(chuàng)建對(duì)象的函數(shù)的引用。指向構(gòu)造函數(shù)。
●Prototype:對(duì)該對(duì)象的對(duì)象原型的引用。
方法:
●HasOwnProperty(property):判斷對(duì)象是不是有某個(gè)屬性。
●IsPrototypeOf(aobject):判斷該對(duì)象是不是另一個(gè)對(duì)象的原型。
●PrototypeIsEnumerable(protype):判斷屬性是否可以用for...in語(yǔ)句枚舉。
●ToString()
●ValueOf()
----------------------------------------------------------------------------------------------------
0007:
聲明數(shù)組的幾種方法:
var array1 = new Array();
var array2 = new Array("Blue","Red","Black");
var array3 = ["Blue","Red","Black"];
----------------------------------------------------------------------------------------------------
0008:
創(chuàng)建日期類型的方法:var myDate = new Date(Date.parse("2007/1/2"));
----------------------------------------------------------------------------------------------------
0009:
URL的編碼和解碼:
var url = new String("http://www.qpsh.com?name=smartkernel");
//編碼:將非標(biāo)準(zhǔn)字符全部編碼
var enUrl = encodeURIComponent(url);//encodeURI(url);
//解碼:轉(zhuǎn)換為原始形式
var deUrl = decodeURIComponent(enUrl);//decodeURI(enUrl);
----------------------------------------------------------------------------------------------------
0010:
ASP.Net中的編碼和解碼:
string url = "http://www.126.com?name=smartkernel";
string enUrl = this.Server.HtmlEncode(url);
string deUrl = this.Server.HtmlDecode(enUrl);
----------------------------------------------------------------------------------------------------
0011:
靜態(tài)方法:JavaScript的靜態(tài)函數(shù),就是聲明給構(gòu)造函數(shù)的函數(shù)
}
Person.say = function(msg)
{
alert(msg);
}
Person.say("你好");
var aPerson = new Person("張三",23);
aPerson.say();
var aStringBuilder = new StringBuilder();
aStringBuilder.append("世界");
aStringBuilder.append("你好");
alert(aStringBuilder.toString());
function MyPerson(name,age)
{
this.ctorFun = Person;
this.ctorFun(name);
delete this.ctorFun;
this.Age = age;
this.sayAge = function()
{
alert(this.Age);
}
this.say = function()
{
alert(this.Name + "|" + this.Age);
}
}
var aMyPerson = new MyPerson("張三",25);
aMyPerson.sayName();
aMyPerson.sayAge();
aMyPerson.say();
function MyPerson(name,age)
{
Person.call(this,name);//或者Person.apply(this,new Array(name));
this.Age = age;
this.sayAge = function()
{
alert(this.Age);
}
this.say = function()
{
alert(this.Name + "|" + this.Age);
}
}
var aMyPerson = new MyPerson("張三",25);
aMyPerson.sayName();
aMyPerson.sayAge();
aMyPerson.say();
function MyPerson(name,age,sex)
{
Person1.call(this,name);
Person2.call(this,sex);
this.Age = age;
this.sayAge = function()
{
alert(this.Age);
}
this.say = function()
{
alert(this.Name + "|" + this.Age + "|" + this.Sex);
}
}
var aMyPerson = new MyPerson("張三",25,"男");
aMyPerson.say();
}
function MyPerson()
{
}
MyPerson.prototype = new Person();//不能有參數(shù)
function MyPerson(name,age)
{
Person.call(this,name);//或者Person.apply(this,new Array(name));
this.Age = age;
this.sayAge = function()
{
alert(this.Age);
}
this.say = function()
{
alert(this.Name + "|" + this.Age);
}
}
MyPerson.prototype = new Person();
var aMyPerson = new MyPerson("張三",25);
aMyPerson.sayName();
aMyPerson.sayAge();
aMyPerson.say();
|
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注