代码使用方法:
0001:
判断一个计算结果是不是无穷大:if(isFinite(999999999*999999999) == true)
----------------------------------------------------------------------------------------------------
0002:
判断是不是数字:if(isNaN("Blue") == true),不是数字则为true,是数字则为false。
----------------------------------------------------------------------------------------------------
0003:
数字的进制转换:
var num = 10;
alert(num.toString()) + "<br>";//十进制
alert(num.toString(2)) + "<br>";//二进制
alert(num.toString(8)) + "<br>";//八进制
alert(num.toString(16)) + "<br>";//十六进制
----------------------------------------------------------------------------------------------------
0004:
将字符串类型转换为数字类型:注意,parseFloat没有进制参数可以选择,都当作十进制处理
var str = "10";
alert(parseInt(str,10));//字符串被当作十进制处理
alert(parseInt(str,2));//字符串被当作二进制处理
----------------------------------------------------------------------------------------------------
0005:
强制类型转换:
var str = "10";
var num = new Number(str);
----------------------------------------------------------------------------------------------------
0006:
Object类的基本属性和方法:所有类都继承自Object,因此都有这些属性和方法。
属性:
●Constructor:对创建对象的函数的引用。指向构造函数。
●Prototype:对该对象的对象原型的引用。
方法:
●HasOwnProperty(property):判断对象是不是有某个属性。
●IsPrototypeOf(aobject):判断该对象是不是另一个对象的原型。
●PrototypeIsEnumerable(protype):判断属性是否可以用for...in语句枚举。
●ToString()
●ValueOf()
----------------------------------------------------------------------------------------------------
0007:
声明数组的几种方法:
var array1 = new Array();
var array2 = new Array("Blue","Red","Black");
var array3 = ["Blue","Red","Black"];
----------------------------------------------------------------------------------------------------
0008:
创建日期类型的方法:var myDate = new Date(Date.parse("2007/1/2"));
----------------------------------------------------------------------------------------------------
0009:
URL的编码和解码:
var url = new String("http://www.qpsh.com?name=smartkernel");
//编码:将非标准字符全部编码
var enUrl = encodeURIComponent(url);//encodeURI(url);
//解码:转换为原始形式
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:
静态方法:JavaScript的静态函数,就是声明给构造函数的函数
}
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();//不能有参数
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();
新闻热点
疑难解答