如何通过 jQuery 禁用选择标签选项?需要帮助
我对选择标签选项有疑问。请任何人通过 jQuery 解决。 假设我有两个选择标签,在第一个选择标签中,我有语言和脚本的选项,在选择的第二个标签中,我有关于语言和脚本的选项。脚本编写。问题是,如果我从第一个选择标签中选择语言,则只有语言选项应该在第二个标签中可见。就像
<select id="Languages">
<option value="0">--Select--</option>
<option value="1">Languages</option>
<option value="2">Scripting</option>
</select>
<select id="Scripting">
<option value="0">--Select--</option>
<option value="1">C#</option>
<option value="2">VB</option>
<option value="3">PHP</option>
<option value="4">jQuery</option>
<option value="5">javascript</option>
</select>
现在,如果我选择语言选项,则唯一的 C#、VB 和PHP 应该是可见的,并且所有其他选项都将被禁用。
I have a query regarding Select tags option. plz any one solve through jQuery.
Suppose i have two select tags, in the first select tags i have options of Languages and script and in the second tag of select i have option regarding languages & scripting. The problem is that if i select languages from 1st select tag than only languages option should be visible in the second tag. Like
<select id="Languages">
<option value="0">--Select--</option>
<option value="1">Languages</option>
<option value="2">Scripting</option>
</select>
<select id="Scripting">
<option value="0">--Select--</option>
<option value="1">C#</option>
<option value="2">VB</option>
<option value="3">PHP</option>
<option value="4">jQuery</option>
<option value="5">javascript</option>
</select>
Now if i select Language option the only C#, VB & PHP should be visible and all other options will be disables.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你可以采取两种方法来解决这个问题。
<选择 id="first_select">
<选项 id="lang"> 语言
<选项 id="脚本>脚本
< /选择>
<选择id =“第二选择”>
<选项 id="lang_1"> 语言 1
<选项 id="script_1>脚本 1
< /选择>
在第一个选择上绑定一个更改事件。
二:几乎相同,但是您对第一个选择元素中的每种类型使用 1 个选择。并在更改哈德并显示合适的哈德。
..弗雷德里克
You could do 2 approches to this.
< select id="first_select">
< option id="lang">Lang
< option id="script>Script
< /select>
< select id="second_select">
< option id="lang_1">Lang 1
< option id="script_1>Script 1
< /select>
The on the first select bind a on change event.
Two: Almost the same, but instead you use 1 select for each of the types in the first select element. And on change hade and show the appropriate one.
..fredrik
这是一个基本模板,配置起来相对容易:
Here's a basic template that makes it relatively easy to configure:
首先查看Selected from jquery 的文章。我想你的代码看起来像这样:
这是伪代码,我的头脑中的代码,你可能需要稍微修改一下,但一般的想法是你会为选项分配一个类,然后使用这些类值来控制第二个表中可用的选项。
编辑:看起来 hide 确实适用于选项,因此您可以分别用 .show() 或 .hide() 替换上面的“disabled = [boolean]”调用。另请查看之前的问题:
使用 jQuery 在选择列表中隐藏选项< /a>
First check out the article on Selected from jquery. I imagine your code will look something like this:
That's psuedo, off-the-top-of-my-head code, you may need to revise it a little, but the general idea is that you would assign a class to the options and use those class values to control which options are available in the second table.
Edit: Looks like hide does work on options, so you might replace "disabled = [boolean]" calls above with .show() or .hide() respectively. Also check out this earlier question:
Hide options in a select list using jQuery
互斥体选择:
mutex selects: