我在将动作添加到动态创建的对象时遇到了一些奇怪的问题。问题是,当我添加它以及分配动作时,动作是自动完成的,而不是通过按下鼠标按钮。现在,在基于以前的功能进行了一些更改之后,我所实现的完全不起作用。
optionsList = {
Elements: new Array(),
El: '',
initialMouseX: undefined,
initialMouseY: undefined,
startX: undefined,
startY: undefined,
dXKeys: undefined,
dYKeys: undefined,
zeroX: undefined,
zeroY: undefined,
draggedObject: undefined,
initListElement: function (element,type)
{
if (!this.Elements[element.id])
{
this.Elements[element.id] = new Array();
console.log("added new element with id: " + element.id);
}
if (typeof element == 'string')//jeśli element jest stringiem
{
element = document.getElementById(element);
}
this.Elements[element.id].type = type;
addEventSimple(this.Elements[element.id],'mousedown',optionsList.showControls);
console.log("element type: " + this.Elements[element.id].type + " id: " + element.id);
return false;
},
showListControls: function(e)
{
var evt = e || window.event;
optionList.showControls(this,evt);
return false;
},
/*******************************************/
/*The function*/
showControls: function(obj,e)
{
console.log("Item pressed id is: " + obj.id);
return false;
}
}
因为整个源代码很长,我把它贴在这里:http: //jsfiddle.net/sebap123/smu3E/0/
错误(或不起作用的功能)位于 JS 代码的底部。我想要实现的是当按下白色文本时会发生一些动作,基于对象的类型或 id。
多次阅读此源代码后,我仍然找不到任何错误所在。
非常感谢您提前