Javascript 如何在创建选项时更改其背景图像?

Javascript 如何在创建选项时更改其背景图像?,javascript,html,background-image,html-select,Javascript,Html,Background Image,Html Select,我正在选择元素中创建一个选项,并尝试更改背景图像 nextItem = document.createElement('option'); nextItem.innerHTML = text; nextItem.style.backgroundImage = "url(icons/add.png);"; nextItem.className = "class1"; 然而,当我使用firebug时,我可以看到实际创建的是: <option class="class1" style="

我正在选择元素中创建一个选项,并尝试更改背景图像

nextItem = document.createElement('option');

nextItem.innerHTML = text;

nextItem.style.backgroundImage = "url(icons/add.png);";

nextItem.className = "class1";
然而,当我使用firebug时,我可以看到实际创建的是:

<option class="class1" style="">text</option>
文本

为什么要创建style属性,但不在其中添加任何信息?

您可以尝试此
nextItem.style.backgroundImage=“url('icons/add.png')”

您可以尝试使用此
nextItem.style.backgroundImage=“url('icons/add.png')”

删除url中的分号

更改:

nextItem.style.backgroundImage = "url(icons/add.png);";
致:


删除url中的分号

更改:

nextItem.style.backgroundImage = "url(icons/add.png);";
致: