在 SAPUI5 中单击时图像按钮 onchange?

Image Buttons onchange when clicked in SAPUI5?

单击时如何更改图像按钮?它应该更改为其他图像按钮。

var offButton =  new sap.ui.commons.Button({
        id : "offIcon",
        icon : "img/off.png" ,
        press :function(e) {
            alert("clicked");
          var noButton = new sap.ui.commons.Button({
            id:"noIcon",
            icon : "img/no.png" ,
            });
    noImage.addStyleClass("noButtonImage");

您正在定义两个按钮,这可能不起作用,检查一下:

var offButton =  new sap.ui.commons.Button({
        id : "offIcon",
        icon : "img/off.png" ,
        press :function(e) { 
                var myBtn = sap.ui.getCore().byId("offIcon");
                myBtn.setIcon(''); // this removes the icon
               }
        });

开关示例:

var offButton =  new sap.ui.commons.Button({
        id : "offIcon",
        icon : "img/off.png" ,
        press :function(e) { 
                var myBtn = sap.ui.getCore().byId("offIcon");
                if (myBtn.getIcon() == '' || myBtn.getIcon == 'null') {
                  myBtn.setIcon('img/off.png');
                } else {
                myBtn.setIcon(''); // this removes the icon
                }
               }
        });