Javascript选择框-使图像显示而不是文本

Javascript选择框-使图像显示而不是文本,javascript,html,css,Javascript,Html,Css,我目前有两个选择框,第一个下拉选择框然后填充第二个选择框。一旦您选择了这两个选项,就会出现一个GO按钮,根据您的选择将您带到一个链接。我想能够改变这个去按钮从文本到图像。其样式如下所示: if (!goButton) { //If the element doesn't exist, make it. goButton = document.createElement('button1'); goButton.innerHTML = "Go!"; goB

我目前有两个选择框,第一个下拉选择框然后填充第二个选择框。一旦您选择了这两个选项,就会出现一个GO按钮,根据您的选择将您带到一个链接。我想能够改变这个去按钮从文本到图像。其样式如下所示:

     if (!goButton) {
    //If the element doesn't exist, make it.
    goButton = document.createElement('button1');
    goButton.innerHTML = "Go!";
    goButton.style.display = "inline-block";
    goButton.style.fontWeight = "500";
    goButton.style.fontcolor = "white";
    item.parentNode.appendChild(goButton); //add it to the parent of the item argument.
    goButton.setAttribute('onclick', 'goButtonGo()');
    goButton.setAttribute('id', 'go-button');
  } else {
    //If it does exist, make sure you can see it.
    goButton.style.display = 'inline-block';
  }
}

任何帮助都将不胜感激,谢谢

使用按钮,您可以设置背景图像

var button=document.createElement'button1'; button.style.display=内联块; button.style.backgroundImage=urlhttps://codepo8.github.io/canvas-images-and-pixels/img/horse.png'; button.style.backgroundSize='封面'; button.style.width='100px'; button.style.height='100px'; document.getElementById'box'.appendChildbutton;
我建议在CSS中保留样式,而不是由JS处理

.goButton {
    font-weight: 500;
    color: white;
    background-image: url("the/url/of/your/image.jpg");
}
.goButton .selected {
    display: inline-block;
}
然后,您只需设置此代码即可管理样式

if (goButton.className) goButton.className =  "selected";
else                    goButton.className += " selected";