js面向对象问题,高人请进
问题:
网页上显示表情,在多个地方。类的构造方法:
function GXFaceBox(faceContener/*表情容器*/,inputId/*显示的目标对象*/){
this.faceTxt = ["[微笑]","[调皮]","[憨笑]","[坏笑]","[可爱]","[阴险]","[偷笑]","[呲牙]","[玫瑰]","[凋谢]","[难过]","[发呆]","[冷汗]","[发狂]","[吐]","[闭嘴]","[疑问]","[擦汗]","[强]","[弱]","[撇嘴]","[色]","[鄙视]","[嘘]","[白眼]","[亲亲]","[OK]","[握手]","[胜利]","[抱拳]"];
this.faceID = 0;
var str = "<div class='mood_list' >";
var i =0;
var rNum = 0;
var left=3;
var top = 3;
for(var i=0;i<30;i++){
if(i%10 ==0 && i>0){
left = 3;
top += 30;
}
//str = str + '<div id="faceDiv_'+i+'" style="float:left;width: 29px;height: 30px;background: url(\'/common/StateBar/images/tiFace.gif\') no-repeat scroll -'+left+'px -'+top+'px transparent;"></div>';
str = str + '<a id="faceDiv_'+i+'" title="'+this.faceTxt[i]+'" class="mood_sp" onmousedown="event.cancelBubble=true;" style="BACKGROUND-POSITION:-'+left+'px -'+top+'px ;"></a>';
left = left + 29;
}
//onmouseover="this.style.border=\'1px red solid\'" onmouseout="this.style.border=\'\'" title="'+faceTxt[i]+'"
str = str + "</div>";
this.faceParent=document.createElement("div");
this.faceParent.id=faceContener;
this.faceParent.style.display="none";
this.faceParent.style.height="0px";
this.faceParent.innerHTML = str;
this.faceParent.style.zIndex =10000;
this.inputContainer = $(inputId);
// faceBox.lastChild.style.background="url(/common/StateBar/images/bxFaceSel.gif) no-repeat 0 -70px";
var parentEl = this.inputContainer.parentNode;
if(parentEl.lastChild == this.inputContainer){
parentEl.appendChild(this.faceParent);
}else{
parentEl.insertBefore(this.faceParent,this.inputContainer.nextSibling);
}
this.faceBox = $(faceContener);
thisObj = this;
for(var i=0;i<30;i++){
$("faceDiv_" + i).onmousedown = function(e){
e = e||event;
e.cancelBubble=true;
thisObj.boxmousedown(this);
};
}
//this.faceBox.attachEvent("onmousedown",function(e){ thisObj.boxmousedown(e); });
// this.faceBox.firstChild.attachEvent("onmousemove",function(e){thisObj.boxmousemove(e);});
//全局容器中加一
//
}
这个是构造方法,不希望换,因为很多地方用到。如何实现.
首先我想到的是在show方法中可以修改目标对象。高人指点。。。。。。。。。。。。
------解决方案--------------------这个是构造方法,不希望换,因为很多地方用到。如何实现. ---- 不希望换,可是你要实现什么呢?
首先我想到的是在show方法中可以修改目标对象。高人指点。 ---- show方法?是你自己另外写的一个函数吗?这是要修改什么目标对象呢?
这些问题你得说清楚啊,要不,谁知道你这是要做啥呢?
------解决方案--------------------ubb标签?
------解决方案--------------------看不懂你想表达什么,也没有看到show方法
既然是在多个地方要用的控件,生成的html要使用随机id,你这样使用固定id是不行的,会重复