這個簡單的JS不能設置「para」的值。我猜getElementByName不起作用。但爲什麼?JavaScript getElementByName不起作用
<script>
function fn()
{
document.getElementById("para").setAttribute("name","hi");
document.getElementByName("hi").setAttribute("value","my value is high");
}
</script>
HTML:
<input type="button" onClick="fn()" value="click me">
<input id="para" type="text" />
菲爾,請[代碼格式正確(http://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks)不要像你那樣使用反引號。 – 2010-06-05 15:05:51
可能重複的[在IE7中的getElementsByName](http://stackoverflow.com/questions/278719/getelementsbyname-in-ie7) – 2010-06-05 15:05:51
感謝您的格式化,我明白了 – Philip007 2010-06-05 15:21:39