2013-11-23 100 views
-1

我有一个下拉菜单,其中的信息来自极其喜欢的作品,但我想添加一个按钮,点击时弹出 跳转到下拉菜单中的下一个选项..我如何做这个?使用另一个按钮的下一个选项下拉框

这是我的下拉框:

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

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

谢谢!在你的DOM

+1

那么你需要一些JavaScript,但你没有发布或显示你试过的东西。走了,我们可以帮助,如果它不工作。 – Utkanos

回答

1

试试这个

<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'); 

});

1

尝试

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()

+0

两种方式似乎都没有工作? –

+0

@NajibBijan将您的代码放入DOM中准备好。从此小提琴中复制代码 - > http://jsfiddle.net/cse_tushar/M3znX/2/ –

相关问题