我使用JavaScript動態創建按鈕;我希望每個按鈕都有自己的背景圖像。我怎樣才能做到這一點?使用動態背景圖像創建按鈕
我到目前爲止的代碼是:
<html>
<body>
<script>
function buttonsCreate() {
for (var i = 0; i <= 10; ++i) {
var button = document.createElement("button");
var Area = document.getElementById("Area");
Area.appendChild(button);
button.setAttribute("onClick", "eventHandlerForButtons('" + i + "');");
}
}
function eventHandlerForButtons(alertText) {
alert(alertText);
}
</script>
<button onClick="buttonsCreate();">Create Buttons</button>
<div id="Area"></div>
</body>
</html>
'圖像在一個數組中' - 在你的代碼中沒有圖像數組 - - 事實上,沒有數組在一個;;; - 如果您說出關於您的代碼不準確的問題,很難提供幫助 –
使問題更易於閱讀。它最初提到在某處存在一組圖像,但它實際上並未顯示,因此需要包含這些圖像。 –