jQuery Selectmenu 插件 - 无法隐藏选择框
我正在使用由 Filament Group 创建的“Selectmenu”插件。我无法提供超链接,因为我在 Stackoverflow 上发布的内容还不够多,无法使用 2 个以上的超链接。
我有 2 个选择框;一份列出软件(工具),一份列出工具版本。我希望能够选择一个工具,显示工具版本选择框并将特定于版本的数据写入屏幕。只要用户在选择版本之前不选择其他工具,这种方法就可以正常工作。
当用户选择工具而不选择版本时,先前版本的选择框不会隐藏。例如,如果用户选择“cgs”,则会显示“cgs 版本”选择框。但是,如果用户没有选择版本而是选择另一个工具(例如“dpss”),则“dpss 版本”选择框会出现,但“cgs 版本”选择框不会隐藏。
它应该像这样简单,但这不起作用:
$("select:not(#cgs)").hide();
我将它放在检查工具版本的 If 语句中。
Javascript Pastie: http://pastie.org/2695842
HTML Pastie: http://pastie.org/2685522
任何帮助都会很大赞赏。
现场演示(使用上面链接的 jQuery 和 HTML):位于 JS Fiddle:http://jsfiddle.net/davidThomas /Na9Wq/。
I am using the "Selectmenu" plugin created by Filament Group. I can't provide a hyperlink because I haven't posted enough on Stackoverflow to use more than 2 hyperlinks.
I have 2 selectboxes; one listing s/w (tool) and one for tool version. I want to be able to select a tool, show the tool version selectbox and write version-specific data to the screen. This is working fine as long as the user does not select another tool before selecting a version.
When the user selects a tool w/out selecting a version, the previous version selectbox does not hide. For instance if the user select "cgs" then the "cgs versions" selectbox shows. But if the user does not select a version and instead selects another tool, say "dpss", the "dpss versions" selectbox appears but the "cgs versions" selectbox does not hide.
It should be as simple as this, which does not work:
$("select:not(#cgs)").hide();
I am placing it inside the If statement that checks for the tool version.
Javascript Pastie: http://pastie.org/2695842
HTML Pastie: http://pastie.org/2685522
Any help would be greatly appreciated.
Live demo (using the above-linked jQuery and HTML): at JS Fiddle: http://jsfiddle.net/davidThomas/Na9Wq/.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果有人感兴趣,我已经解决了。我认为我的问题与 Selectmenu 插件 有关。我从示例代码开始,并尝试使我的代码适合其结构。我确信有人比我拥有更多 Javascript 经验,可以将其转化为更少的代码行。
无论如何,秘密是为包含“工具”选择框的字段集创建一个 ID,然后在选择该工具后立即调用以下代码:
这会隐藏除所选工具的字段集和选择框之外的所有内容。
$('select:not(#tool, ' + tool + ')').hide();
在这里不起作用。另外,我添加了“lasttool =工具;”对于第一次运行,否则将根据用户选择的顺序显示多个版本选择框。
这两项更改允许删除其他使代码变得冗长的脚本。最后,我不是 100% 确定为什么这会起作用,但我很高兴它能起作用。下面是最终的 Javascript 和 HTML。
Javascript
HTML
In case anyone is interested, I have it solved. I think my problem has something to do w/ the Selectmenu plugin. I started w/ example code and tried to make my code fit w/in it's structure. I'm sure someone w/ more Javascript experience than I can turn this into fewer lines of code.
Anyway, the secret was to create an ID for the fieldset containing the "tool" selectbox and then call the following code as soon as the tool is selected:
This hides everything except the fieldset and selectbox for the selected tool.
$('select:not(#tool, ' + tool + ')').hide();
does not work here.Also, I added "lasttool = tool;" for 1st run through, otherwise multiple version selectboxes will show depending on order in which user selects them.
These two changes allowed other scripts to be removed that made the code verbose. In the end, I'm not 100% sure why this works but I'm glad it does. Below is the final Javascript and HTML.
Javascript
HTML