在下拉列表中显示其他字段 [英] Display additional field on dropdown select

查看:103
本文介绍了在下拉列表中显示其他字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!
我在html文件中有一个基本的表单设置.我想做的是,如果用户在下拉框中选择一个特定的选项,然后在页面上显示一个附加字段.这可能吗?

谢谢!
Ross

Hello!
I have a basic form setup in an html file. What I want to do is if a user selects a specific option in a dropdown box, then display an additional field on the page. Is this possible?

Thanks!
Ross

推荐答案

是的,很有可能.

例如,如果您在选择中选择其他"作为选项,则需要显示一个文本框,如果需要,可以在其中填充其他描述.

您需要执行以下操作:
1.为select
附加一个Javascript的"onchange"处理程序 2.无论何时选择任何内容,都会触发"onchange",您可以检查选择的值
3.如果选定的值是需要一些额外步骤的值,请执行此操作,否则跳过休息.
4.如果是特定步骤,则通过Javascript访问另一个控件(如文本框),将其显示属性设置为true,以便可以添加更多详细信息.

完毕!试试吧!
Yes, very much possible.

For example, if you select ''Others'' as an option in the select then a textbox needs to be shown where one can fill any description of other if needed.

You need to do:
1. Attach a Javascript ''onchange'' handler for the select
2. Whenever anything is selected the ''onchange'' will be triggered and you can check the selected value
3. If the selected value is the one that needs some extra steps then do it or else skip rest.
4. If it is the specific step, then via Javascript, access the other control (like a textbox), set its display property as true such that one can add more details.

Done! Try!


这篇关于在下拉列表中显示其他字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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