用javascript中的文本菜单替换下拉菜单

用javascript中的文本菜单替换下拉菜单,javascript,javascript-events,Javascript,Javascript Events,如果有人选择“其他”选项,我试图用文本字段替换我的下拉菜单。现在在我的代码中,我用一个段落元素替换它,因为我太懒了,找不到设置文本字段的确切构造函数参数。但是,当选择“其他”时,不会发生任何事情 有人知道这是怎么回事吗 <html> <head> <script type="text/javascript"> function testfunc(arg) { if(arg.value == "other") { document.thi

如果有人选择“其他”选项,我试图用文本字段替换我的下拉菜单。现在在我的代码中,我用一个段落元素替换它,因为我太懒了,找不到设置文本字段的确切构造函数参数。但是,当选择“其他”时,不会发生任何事情

有人知道这是怎么回事吗

<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>

函数testfunc(arg){
如果(参数值=“其他”){
document.thing.replaceChild(document.test、document.thing.selection)
}
否则{
警惕(“东西”)
}
}
对
不
其他
lkjsdf

此处的HTML代码:

<select id="arg" onChange="show_txt('arg','arg1');">
<option>yes</option>
<option>No</option>
<option>Other</option>
</select>
<input type="text" id="arg1" style="display:none;">

对
不
其他

函数应该是这样的!其他而不是其他!它区分大小写(无论如何在linux上…不确定其他操作系统),否则谢谢…一直在寻找这个…酷的显示/隐藏方式

<script type="text/javascript">
function show_txt(arg,arg1)
{
if(document.getElementById(arg).value=='Other')
{
document.getElementById(arg1).style.display="block";
document.getElementById(arg).style.display="none";
}
else
{
document.getElementById(arg).style.display="block";
document.getElementById(arg1).style.display="none";
}
}
</script>

函数show_txt(arg,arg1)
{
if(document.getElementById(arg.value=='Other'))
{
document.getElementById(arg1.style.display=“block”;
document.getElementById(arg.style.display=“无”;
}
其他的
{
document.getElementById(arg.style.display=“block”;
document.getElementById(arg1.style.display=“无”;
}
}

嘿,我看到了你的代码,你需要一些练习

你忘了关塔格。第二,始终使用ID而不是名称。第三,表单无法访问tagh。第四,不能使用表单前缀访问表单以外的元素。第五,您可以创建tagh dynamicali,也可以在页面上使用display none进行播放。检查我的代码。这也是动态生成它所能做的

var newP=document.createElement(“p”); var txt='lkjsdf'; var newT=document.createTextNode(txt); newP.appendChild(newT)


函数testfunc(arg){
如果(参数值=“其他”){
document.thing.removeChild(document.thing.selection);
document.getElementById('testText').style.display='inline';
}
否则{
警惕(“东西”);
}
}
对
不
其他
lkjsdf

<script type="text/javascript">
function show_txt(arg,arg1)
{
if(document.getElementById(arg).value=='Other')
{
document.getElementById(arg1).style.display="block";
document.getElementById(arg).style.display="none";
}
else
{
document.getElementById(arg).style.display="block";
document.getElementById(arg1).style.display="none";
}
}
</script>
<html>
<head></head>
<script type="text/javascript">
function testfunc(arg) {
    if(arg.value == "other") {
        document.thing.removeChild(document.thing.selection);
        document.getElementById('testText').style.display='inline';
    }
    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>
<p id="testText" style="display:none">lkjsdf</p>
</form>
</body>
</html>