【问题标题】:Next option dropdown box using another button使用另一个按钮的下一个选项下拉框
【发布时间】:2013-11-23 19:16:59
【问题描述】:

我有一个下拉菜单,其中包含我想要的信息,但我想添加一个按钮 单击时跳转到该下拉菜单中的下一个选项.. 我该怎么做?

这是我的下拉框:

<select name="the_name">
     <?php foreach ( $results as $option ) : ?>
     <option value="<?php echo $option->ID; ?>"><?php echo $option->titel; ?></option>
     <?php endforeach; ?>
</select>

所以,我喜欢做的是单击此菜单的按钮,例如上一个/下一个,我该怎么做?

谢谢!

【问题讨论】:

  • 好吧,您需要一些 JavaScript,但您没有发布任何内容或展示您尝试过的内容。试一试,如果不成功,我们可以提供帮助。

标签: javascript php jquery html drop-down-menu


【解决方案1】:

试试这个:

在你的 DOM 中:

<select id="the_name">
    <option selected="selected">1</option>
    <option>2</option>
</select>

<button id="next">next</button>

在你的 jquery 中,按钮事件

$('#next').click(function(){
     $('#the_name').find('option:selected').prop('selected',"").next().prop('selected','selected');

});

【讨论】:

    【解决方案2】:

    试试

    fiddle Demo

    var dd = $('#the_name');
    var max_len = dd.find('option').length;
    $('#change').click(function () {
        var x = dd.find('option:selected').index();
        if (max_len == x + 1) x = -1;
        dd.find('option').eq(x + 1).prop('selected', true);
    });
    


    .index()

    .prop()

    .find()

    .eq()

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-22
    • 2013-11-12
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    相关资源
    最近更新 更多