js给看段代码,Div拖动 本帖最后由 wang_137 于 2011-10-20 12:50:31 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var aa=function(){ this.say=function(){alert(12)}}aa.prototype.say1=function(){alert(125)}var b=new aa();b.say();b.say1() 我那样写该怎么改啊,因为我有好多方法要加,我不想每次都写,prototype var aa={};aa.say=function(){};aa.say1=function(){};aa.say2=function(){}; function aa(){ this.say=function(){alert(12)}}aa.prototype={constructor:aa,say1:function(){alert(125)}}var wori=new aa()wori.say();wori.say1(); 楼主理解错prototype了。。只有构造函数才有prototype原型刚才你aa.prototype={say1:function(){alert(125)}只是给aa添加了一个名为prototype的成员变量var aa={say:function(){alert(12)}}如果想添加say1方法,只需添加一个名为say1的成员变量就可以aa.say1 = functino(){ //dosth} var moveBox={ version:1.0, source:null, movable:false,//movable mousePosition:null, mpSource:null,//mouse position to source Client:function(s){//bound element moveBox.source=$("#"+s); this.register(this); } } moveBox.Client.prototype ={ getMPSource:function(e){//mouse position to source return { rx:e.offsetX?e.offsetX:e.layerX, ry:e.offsetY?e.offsetY:e.layerY } }, getMousePosition:function(e){ if(e.pageX || e.pageY){ return {x:e.pageX, y:e.pageY}; } return { x:e.clientX + document.body.scrollLeft - document.body.clientLeft, y:e.clientY + document.body.scrollTop - document.body.clientTop } }, register:function(o){ moveBox.source.mousedown(function(e){ moveBox.movable=true; moveBox.mpSource=o.getMPSource(e); }); moveBox.source.mouseup(function(e){ moveBox.movable=false; moveBox.mpSource=null; }); moveBox.source.mousemove(function(e){ if(moveBox.movable){ moveBox.mousePosition=o.getMousePosition(e); moveBox.source.css("left",moveBox.mousePosition.x-moveBox.mpSource.rx); moveBox.source.css("top",moveBox.mousePosition.y-moveBox.mpSource.ry); } }); $(document).mouseup(function(){ if(moveBox.movable) moveBox.movable=false; }); } }var client=new moveBox.Client("move");终于完成了,兼容浏览器,但感觉写的有点别扭贴出来只是希望大牛们能改的优雅些 楼主的代码里面aa是一个实例,并不是一个构造函数。有两个方法可以改正楼主的代码:var aa={ say:function(){alert(12);}};aa.__proto__.say1=function(){ alert(125);}aa.say();aa.say1();或者function aa(){ this.say = function(){alert(12);}}aa.prototype={ say1:function(){ alert(125); }};var a = new aa();a.say();a.say1();具体楼主可以看看关于原型的内容。 aa 是对象 没有prototype指针吧只有方法才有这个 来!看谁的解决这个逻辑问题的代码最少或者最简单。 jquery post传值给java,可是取不到 如何根据jsp列表中的一行的某一个数据改变改行的颜色 JS动态添加。删除后取值问题 高手救命:为啥我加入外部的动态广告后老是出错? 这个为何? 被alert出来是2005 1975? 我想在iframe中动态引入文件。 怎么改变文字的字体?急问 请问table1.children(0).children(i)中的children(0)代表什么意思 TO:net_lover(孟子E章),详情请入内! 这两种代码写法为什么会有这么大的区别? 关于${param}的问题。
var aa=function(){
this.say=function(){alert(12)}
}
aa.prototype.say1=function(){
alert(125)
}
var b=new aa();
b.say();
b.say1()
aa.say=function(){};
aa.say1=function(){};
aa.say2=function(){};
function aa(){
this.say=function(){alert(12)}
}
aa.prototype={
constructor:aa,
say1:function(){
alert(125)
}
}
var wori=new aa()
wori.say();
wori.say1();
刚才你
aa.prototype={
say1:function(){
alert(125)
}只是给aa添加了一个名为prototype的成员变量
var aa={
say:function(){alert(12)}
}如果想添加say1方法,只需添加一个名为say1的成员变量就可以aa.say1 = functino(){
//dosth
}
version:1.0,
source:null,
movable:false,//movable
mousePosition:null,
mpSource:null,//mouse position to source
Client:function(s){//bound element
moveBox.source=$("#"+s);
this.register(this);
}
}
moveBox.Client.prototype ={
getMPSource:function(e){//mouse position to source
return {
rx:e.offsetX?e.offsetX:e.layerX,
ry:e.offsetY?e.offsetY:e.layerY
}
},
getMousePosition:function(e){
if(e.pageX || e.pageY){
return {x:e.pageX, y:e.pageY};
}
return {
x:e.clientX + document.body.scrollLeft - document.body.clientLeft,
y:e.clientY + document.body.scrollTop - document.body.clientTop
}
},
register:function(o){
moveBox.source.mousedown(function(e){
moveBox.movable=true;
moveBox.mpSource=o.getMPSource(e);
});
moveBox.source.mouseup(function(e){
moveBox.movable=false;
moveBox.mpSource=null;
});
moveBox.source.mousemove(function(e){
if(moveBox.movable){
moveBox.mousePosition=o.getMousePosition(e);
moveBox.source.css("left",moveBox.mousePosition.x-moveBox.mpSource.rx);
moveBox.source.css("top",moveBox.mousePosition.y-moveBox.mpSource.ry);
}
});
$(document).mouseup(function(){
if(moveBox.movable)
moveBox.movable=false;
});
}
}
var client=new moveBox.Client("move");
终于完成了,兼容浏览器,但感觉写的有点别扭
贴出来只是希望大牛们能改的优雅些
say:function(){alert(12);}
};
aa.__proto__.say1=function()
{
alert(125);
}
aa.say();
aa.say1();或者function aa()
{
this.say = function(){alert(12);}
}
aa.prototype={
say1:function(){
alert(125);
}
};
var a = new aa();
a.say();
a.say1();具体楼主可以看看关于原型的内容。
只有方法才有这个