我試圖用一個文本字段替換下拉菜單,如果有人選擇「其他」選項。現在在我的代碼中,我用它代替了一個段落元素,因爲我懶得找到設置文本字段的確切構造函數參數。但是,選擇「其他」時不會發生任何事情。用javascript中的文本菜單替換下拉菜單
有沒有人知道這有什麼問題?
<html>
<head>
<script type="text/javascript">
function testfunc(arg) {
if(arg.value == "other") {
document.thing.replaceChild(document.test, document.thing.selection)
}
else {
alert("stuff")
}
}
</script>
<body>
<form name="thing">
<select name="selection" onchange="testfunc(document.thing.selection.options[document.thing.selection.selectedIndex])">
<option>yes</option>
<option>no</option>
<option>other</option>
</select>
</form>
<p name="test">lkjsdf</p>
</body>
</html>
這是僞代碼嗎? – Lazarus 2010-09-11 07:34:50