Javascript 根据下拉选项显示更多文本框?
我不知道这在 Javascript 中是否可行,但我正在努力实现这一目标。我不知道术语,所以我想我会用伪代码将其发布在这里,以帮助您理解我想要实现的内容。
伪代码:
- 用户从下拉菜单中选择选项。
- 如果选择符合条件,
- 则将文本框添加到表单中,
- 否则,如果选择是其他内容,
- 则添加具有 NULL 值的不可见文本框
我想自己编写代码,但如果您可以发布一些参考资料或链接,因为我没有对 Javascript 做太多工作。
谢谢
I don't know if this is possible in Javascript but I am trying to achieve this. I don't know the terminology so I thought I would post it on here with pseudo code to help you understand what I want to implement.
Pseudo Code:
- User Selects Option from pull down.
- If selection matches criteria
- Add text boxes to the form
- Else if selection is something else
- Add invisible text box with NULL value
I would like to code it myself but if you could post some reference material or links as I have not done much with Javascript.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于您的第一个和第二个条目,请搜索“html select onchange”。
您需要查看 document.createElement 中的“将文本框添加到form”
要使文本框不可见,请查看 CSS
display
属性,将其设置为none
或块(或内联)
我试图在没有代码示例的情况下使这个答案非常简短,因为听起来您想自己做。如果您想要更多示例,请在我的答案中添加评论。
编辑
另外值得注意的是,除了 document.createElement 之外,您还需要查看
appendChild
将创建的元素添加到 HTML 元素,很可能是页面中的某些 FORM 元素。For your first and second entries, google for 'html select onchange'.
You'll want to check out document.createElement for "Add text boxes to the form"
To make your text box invisible, check out the CSS
display
property, setting it tonone
orblock (or inline)
I've tried to keep this answer very short without code samples because it sounds like you want to do it yourself. Add a comment to my answer if you want more of an example.
EDIT
Also of note, along with document.createElement, you will want to look at
appendChild
to add the created element to an HTML element, most likely some FORM element in your page.