如何根据rails3中的下拉选择显示/隐藏文本字段
根据 Rails3 中的下拉选择显示/隐藏文本字段的最佳方法是什么?
这是代码
<label>Album </label>
<%= select_tag "album", options_for_select(@album_fields, params[:album])" %>
<!--ONLY DISPLAY the label and text_field if one of the selection IS SELECTED-->
<label>New Album Name: </label>
<%= text_field "new_album_name", params[:new_album_name], :id =>"albumname" %>
谢谢
What is the best way to Show/Hide text field based on drop down selection in rails3?
here is the code
<label>Album </label>
<%= select_tag "album", options_for_select(@album_fields, params[:album])" %>
<!--ONLY DISPLAY the label and text_field if one of the selection IS SELECTED-->
<label>New Album Name: </label>
<%= text_field "new_album_name", params[:new_album_name], :id =>"albumname" %>
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您在浏览器中启用了 JavaScript,则可以使用 jQuery 来完成此操作。
基本上,您挂钩下拉列表的 change 事件,当发生这种情况时,您检查下拉列表,并根据下拉列表中选择的内容显示或隐藏文本字段。
像这样的东西:
Assuming you have JavaScript enabled in the browser, you can do this with jQuery.
Basically you hook into the drop-down's change event, and when that happens, you check the value of the drop-down and either show or hide the text-field based on what was selected in the drop-down.
Something like: