Сделать выбранным элемент списка.
Привет всем!
Задача такая: при клике на кнопку, должен выбраться пункт списка и открыться скрытый блок содержимого. Сейчас атрибут списка устанавливается, но элемент списка не выбран и скрытый блок не отображается. Кто подскажет, как решить?
<select id="select" class="Validate_Required " name="actSelect" aria-required="true" onChange="Selected(this)">
<option value="" selected="selected">-</option>
<option value="1">Открыть блок 1</option>
<option value="2">Открыть блок 2</option>
</select>
<div id='Block1' style='display: none;'>
Блок 1
</div>
<div id='Block2' style='display: none;'>
Блок 2
</div>
<button onclick="
$('#select option[value=2]').attr('selected', 'selected');
return false;">Выбираем 2-ый элемент!</button>
function Selected(a) {
var label = a.value;
if (label==1) {
document.getElementById("Block1").style.display='block';
document.getElementById("Block2").style.display='none';
} else if (label==2) {
document.getElementById("Block1").style.display='none';
document.getElementById("Block2").style.display='block';
} else {
document.getElementById("Block1").style.display='none';
document.getElementById("Block2").style.display='none';
}
}
|
webmanss,
Посмотрите http://javascript.ru/forum/dom-windo...-u-select.html |
| Часовой пояс GMT +3, время: 06:09. |