用javascript中的文本菜单替换下拉菜单 [英] replacing a dropdown menu with a text menu in javascript

查看:78
本文介绍了用javascript中的文本菜单替换下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人选择其他选项,我正在尝试用文本字段替换下拉菜单。现在在我的代码中我用它替换了一个段落元素,因为我太懒了,无法找到用于设置文本字段的确切构造函数参数。但是,当选择其他时没有任何反应。

I'm trying to replace a drop down menu I have with a text field if someone chooses the "other" option. Right now in my code I have it replacing it with a paragraph element because I'm too lazy to find the exact constructor arguments for setting up a text field. However, when "other" is selected nothing happens.

有人知道这有什么问题吗?

Does anyone know what's wrong with this?

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


推荐答案

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

the function should be like this! Other not other ! its case sensitive (on linux anyway...not sure about other os) Otherwise thanks...been looking for this...cool way of show/hide

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

这篇关于用javascript中的文本菜单替换下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆