在鼠标悬停时设置背景图像

Set the background image on mouse over

我想动态设置按钮的背景图片。 (不使用 CSS 类)。

我试图通过设置按钮的 style.backgroundImage 属性 来实现这一点,如下所示。 getOnMouseOverImage 绑定到 onmouseover 事件,按钮作为 this.

传递
myapp.ui.Button.prototype.getOnMouseOverImage = function(event) {
    event.target.style.backgroundImage = "url( \'" + myapp.core.ImageStore.getInstance().getImageURL(this.buttonId) + "\')'"
    event.preventDefault();
    event.stopPropagation();
    }

上面的代码好像没有改变按钮的backgroundImage 属性。我该如何实现?

在我看来你有一个额外的'

event.target.style.backgroundImage = "url( \'" + myapp.core.ImageStore.getInstance().getImageURL(this.buttonId) + "\')**'**"

我觉得应该是这样的

 event.target.style.backgroundImage = "url( \'" + myapp.core.ImageStore.getInstance().getImageURL(this.buttonId) + "\')"

不确定这是否是问题所在,但由于我无法发表评论,所以我将 post 作为答案。

编辑:事实上,我什至不确定你是否需要 apostrophe's

 event.target.style.backgroundImage = "url(" + myapp.core.ImageStore.getInstance().getImageURL(this.buttonId) + ")"