1
我收到了一個切換onclick函數的圖像。被調用的函數是一個對象的方法。 我的問題:我不知道對象的名稱,所以我怎麼能Javascript onclick依賴於對象的方法
初始HTML代碼:
<img id="someID" [...] onClick="someObject.aFunction();" />
結果想:
<img id="someID" [...] onClick="someObject.otherFunction();" />
我目前使用Javascript(解決方法) :
someClass.prototype.aFunction() = function() {
button = document.getElementByID('someID');
button.setAttribute("onclick", button.getAttribute('onclick').split('.')[0]+'.otherFunction()');
}
不是很好,但它現在的作品。有更好的解決方案