2
我試圖讓我用下面的代碼點擊圖像的ID獲取圖像ID:Konva從點擊事件
theImg.on('click', function() {
alert($(this).attr('id')); //Should show 'IDofImg'
});
的Konva代碼是這樣的:
var theImg = new Konva.Image({
image: imageObj,
x: stage.getWidth()/2 - 200/2,
y: stage.getHeight()/2 - 137/2,
opacity: 0.8,
shadowColor: 'black',
shadowBlur: 5,
id: 'IDofImg',
shadowOffset: {
x: 0,
y: 0
},
startScale: 1,
shadowOpacity: 0.6,
draggable: true
});
正如你所看到的,我有id:'IDofImg',在圖像的製作中,但它似乎不輸出所需的ID。
function() {
// setting
if (arguments.length) {
this[setter](arguments[0]);
return this;
}
// getting
else {
return this[getter]();
}
}
我缺少什麼:
上點擊後它目前輸出呢?
** ** this.id仍然產生相同的結果作爲OP。 – StealthRT
是的,** this.id()**確實得到了圖像ID很好。請做出正式答覆,以便我可以給你適當的獎勵。 – StealthRT
您的歡迎,添加了答案。 –