我將從xml讀取標籤並將其分配給變量,ID。javascript中的按鈕值變量
ID=(x[i].getElementsByTagName("ID-NUM")[0].childNodes[0].nodeValue);
我怎麼能使用變量,ID,作爲按鈕值顯示?
document.write("<input type = button value = ID style='width:100'><br><br>");
請讓我知道如果我不清楚,謝謝。
我將從xml讀取標籤並將其分配給變量,ID。javascript中的按鈕值變量
ID=(x[i].getElementsByTagName("ID-NUM")[0].childNodes[0].nodeValue);
我怎麼能使用變量,ID,作爲按鈕值顯示?
document.write("<input type = button value = ID style='width:100'><br><br>");
請讓我知道如果我不清楚,謝謝。
你需要把該變量爲字符串,你寫出來
document.write("<input type='button' value='" + ID + "' style='width:100%'/><br/><br/>");
document.write("<input type='button' value='" + ID + "' style='width:100;' />
非常感謝伊恩,它工作。 – newMe 2010-07-15 21:07:29
另外,如果你已經有了按鈕對象寫出來,就可以直接使用對象模型:
document.getElementById("idOfButtonObject").value = ID;
非常感謝EpicoxyMORON(nice sn),我沒有按鈕對象。我會在需要時使用它。 – newMe 2010-07-15 21:08:25
請勿使用document.write
在頁面上插入任何東西。這是有問題的,因爲如果您在構建對象模型後執行此操作,它將清除整個文檔並創建一個新文檔。而是使用DOM方法來創建一個按鈕。
var input = document.createElement('input');
input.type = 'button';
input.value = ID; // set the ID
input.style = 'width: 100';
document.body.appendChild(input); // add to page
非常感謝Anurag,我想現在可以繼續使用document.write了。我將繼續使用DOM方法。 – newMe 2010-07-15 21:09:23
非常感謝拉斯,它的工作。如果我有任何問題,我會通知您,再次感謝。 – newMe 2010-07-15 21:05:58