将 jQuery 添加到表单以显示/隐藏下拉菜单

发布于 2024-10-10 12:54:36 字数 1377 浏览 0 评论 0原文

我正在尝试向 Wordpress 站点添加一些 jQuery,以便当用户在顶部下拉菜单中选择某个选项(软件)时,另一个选项会出现在其下方。

我正在使用以下代码 -

<p id="parent-menu">
    <select name='cat' id='cat' class='dropdown'  tabindex="40">
        <option value='-1'>Select a Category</option>
        <option class="level-0" value="13">Software problem</option>
        <option class="level-0" value="14">Hardware problem</option>
        <option class="level-0" value="15">Suggestion</option>
        <option class="level-0" value="16">General query</option>
    </select>
</p>
<p id="toggle-menu">
    <select name='cat' id='cat' class='dropdown'  tabindex="50">
        <option value='-1'>Select a Program</option>
        <option class="level-0" value="6">BigHand</option>
        <option class="level-0" value="7">IRIS</option>
        <option class="level-0" value="8">MS Outlook</option>
        <option class="level-0" value="9">MS Word</option>
        <option class="level-0" value="10">MS Excel</option>
        <option class="level-0" value="11">Oyez</option>
        <option class="level-0" value="12">Internet Explorer</option>
    </select>
</p>

如果有人可以帮助我做到这一点,我将不胜感激。

谢谢。

I am trying to add some jQuery to a Wordpress site so that when a user selects a certain option (Software) in the top dropdown menu, another appears under it.

I am using the following code -

<p id="parent-menu">
    <select name='cat' id='cat' class='dropdown'  tabindex="40">
        <option value='-1'>Select a Category</option>
        <option class="level-0" value="13">Software problem</option>
        <option class="level-0" value="14">Hardware problem</option>
        <option class="level-0" value="15">Suggestion</option>
        <option class="level-0" value="16">General query</option>
    </select>
</p>
<p id="toggle-menu">
    <select name='cat' id='cat' class='dropdown'  tabindex="50">
        <option value='-1'>Select a Program</option>
        <option class="level-0" value="6">BigHand</option>
        <option class="level-0" value="7">IRIS</option>
        <option class="level-0" value="8">MS Outlook</option>
        <option class="level-0" value="9">MS Word</option>
        <option class="level-0" value="10">MS Excel</option>
        <option class="level-0" value="11">Oyez</option>
        <option class="level-0" value="12">Internet Explorer</option>
    </select>
</p>

Id be greatful if someone could help me to do this.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

晨与橙与城 2024-10-17 12:54:36

我不太确定 wordpress 如何处理 JQuery,但如果我用 PHP 编写它,它会是这样的。我会将分类法更改为 id 或 value。查询将进入我的按钮单击。您需要更改每个点击实例的 ID。

$(".class#id").toggle();
$(".dropdown#software").toggle();

好的。那么关于你的新信息。因为有一个特定的 id 我可以使用。当选择选项 13 时,您需要添加一些内容来检查代码页。选择该选项后,您将需要类似这样的东西。

$("#toggle-menu").toggle();

或者

$("#toggle-menu").show();

现在这里的想法是,如果您基于使用toggle()选择选项来执行此操作或事件,将根据选择显示或隐藏切换菜单,即我在它出现后选择了它,我取消选择或再次选择它菜单消失。使用 show() 将使切换菜单出现,但如果取消选择则不会隐藏它,在这种情况下,您需要在所有其他事件选择中使用 hide() 来隐藏切换菜单

I am not exactly sure on how wordpress handles JQuery but if I was writing this in PHP it would be something like. I would change taxonomy to id or value. And the query would go inside my button click. You would need to change your id for each click instance.

$(".class#id").toggle();
$(".dropdown#software").toggle();

ok. So on your new info. Since there is a specific id I can use. You will need to include something to check your code page for when the option 13 is selected. When that option is selected you would need something like this.

$("#toggle-menu").toggle();

or

$("#toggle-menu").show();

Now the idea here is that if you have this action or event based on selection of option using toggle() will show or hide toggle-menu depending on the selection, ie i selected it once it will appear, i deselect or select it again menu disappears. Using show() will make the toggle-menu appear but not hide it if deselected, in which case you would want to use a hide() in all other event selections to hide the toggle-menu

想念有你 2024-10-17 12:54:36

如果您使用 jQuery UI,您可能会发现 Eric Hynds 插件很有用: http://www .erichynds.com/jquery/jquery-ui-multiselect-widget/

If you use jQuery UI you might find Eric Hynds plugin useful: http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/

荆棘i 2024-10-17 12:54:36

假设切换菜单不关心第一个菜单中选择的内容,您想要的是这个

$('#parent-menu').change(function(event)
{
  $('#toggle-menu').show();
});

$('#toggle-menu').change(function(event)
{
  var selections = $('#parent-menu').val() + ' ' + $('#toggle-menu').val();
  alert(selections);
});

Assuming toggle menu doesnt care what was selected in the first menu, what you want is this

$('#parent-menu').change(function(event)
{
  $('#toggle-menu').show();
});

$('#toggle-menu').change(function(event)
{
  var selections = $('#parent-menu').val() + ' ' + $('#toggle-menu').val();
  alert(selections);
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文