<script>
//------------------------------------------------------
var my user=new myclass(1,'yandavid')
user.speak();
//------------------------------------------------------
//------------------------------------------------------
var
create:function(){return function(){//实际上把所有的属性定义到intiliaze方法(实际上是一个类)中,
this.initialize.apply(this,arguments); //然后通过对象冒充方式继承该类
}}}
/*
建立空类
先实例化超类,再把超类中的方法复制到子类中去,注意,实际上prototype类定义机制中并没有直接定义
类的属性是通过intilize方法,而且所有的方法都直接定义在prototype中,所以直接用原型链方式
*/
Object.extend=function(destination,source){for(property in source){destination[property]=source[property];}return destination;}
var Pirate = Class.create();
Object.extend(Pirate.prototype,{
initialize: function(name){this.name = name;},
speak:function(message){return this.name+':'+message+', yarr!';}
}
);
var a=new Pirate("sss");
alert(a.speak("Pirate"));
//------------------------------------------------------
var Person = Class.create();
Person.prototype = {/*把方法定义到prototype中,注意,是通过initalize方法初始化类的属性 */
initialize: function(name) {
this.name = name;},
say: function(message) {
return this.name + ': ' + message;}
};
var guy = new Person('Miro');
alert(guy.say('hi'));
//------------------------------------------------------
</script>
js获取url里的查询参数值 (两种方法)
String.prototype.getQuery = function(name){var reg=new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); var r = this.substr(this.indexOf("\?")+1).match(reg); if (r!=null) return unescape(r[2]); return null;}
if(document.location.href.getQuery("CardID"))
{
document.location.href='AnotherCard.aspx';
}
function getParameter(sProp) {
var re = new RegExp( sProp + "=([^\&]*)", "i" );
var a = re.exec( document.location.search );
if (a == null) return null;
return a[1];
}
js设置url参数
function setParameter(url, param, v)
{var re = new RegExp("(\\\?|&)" + param + "=([^&]+)(&|$)", "i");var m = url.match(re);if (m){return (url.replace(re, function($0, $1, $2) { return ($0.replace($2, v)); } ));}else{if (url.indexOf('?') == -1){return (url + '?' + param + '=' + v);}else{return (url + '&' + param + '=' + v);}}}