автопереключение <select>
всем привет, вот есть выпадающее меню
<select id="option"> <option value="first">first</option> <option value="second">second</option> <option value="third">third</option> <option value="fourth">fourth</option> <option value="fifth">fifth</option> </select> возможно ли сделать кнопки, которые будут переключаться на следующую страницу (first,second,third и тд..) и наоборот p.s. - на самом деле пунктов в меню намного больше, что и создаёт неудобство переключать их всё время |
видимо как-то так:
функция сдвига function action(shift) { var select = document.getElementById('my_Select_0'); for(var i=0, len=select.options.length; i<len; i++) if(select.options[i].value == select.value) { if((i+shift>0)&&(i+shift<len)) { select.value = select.options[i+shift].value; break; } } } и соответственно кнопка назад вызывает ее с shift=-1, а вперед - с 1 |
Цитата:
<select id="option"> <option>first</option> <option>second</option> <option>third</option> </select> <button class="previous">←</button> <button class="next">→</button> <script> window.onload = function () { var sel = document.body.children[0]; document.body.onclick = function (e) { e = e || event; var target = e.target || e.srcElement; if (target.className == 'previous') { if (sel.selectedIndex != 0) { sel.selectedIndex--; } } else if (target.className == 'next') { if (sel.selectedIndex != sel.children.length - 1) { sel.selectedIndex++; } } } } </script> PS: http://javascript.ru/formatting |
Цитата:
|
Часовой пояс GMT +3, время: 12:25. |