将 jQuery 与
我找到了一个 jQuery 代码,它允许我检查某个单选/复选框是否被选中,然后根据选择显示其他内容。有没有办法使用
谢谢。
I found a jQuery code which allows me to check id a certain radio/checkbox is checked, and then show something else based on the selection. Is there a way to do this with a <select>
option? For instance, if I have a select box that has "Bread", "Milk", and "water" as the options, and the user clicks "bread", it would show "BREAD is $2.99", but if you select "Milk", it'll say "MILK is 2.49". The code is at http://jsfiddle.net/U9Jsh/.
Thank You.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然。您可以在 select 和 $(this).val() 中使用 .change() 处理程序处理程序。请参阅这个小提琴,了解根据面包和牛奶进行变化的示例。这是一个独立的小示例,不是基于您的小提琴,应该可以帮助您入门。您还可以使用“option:selected”选择器。
Sure. You can use the .change() handler on the select and $(this).val() in the handler. See this fiddle for an example that shows changing based on bread and milk. It's a small self-contained example not based off of your fiddle that should get you started. You can also use the "option:selected" selector.
使用 $('select option:selected') 获取当前选定的一个或多个选项(如果是多选)。
use $('select option:selected') to get the currently selected option or options (if it is a multiselect).