Положите opt2
в кавычки для val()
. Это появляется как ошибка, потому что это undefined
.
$('.reset').click(function () {
$('select[name=one]').val('opt2');
});
Вы просили другие методы, но я знаю только один. Этот метод не требует jQuery для работы (обратите внимание, что [0]
захватывает обычный Object
, а не jQuery, обернутый Object
).
//Without jQuery... pretty sure I'm correct with the second method, but I'm rusty on that one.
document.getElementById('formID').one.selectedIndex = 0; // Sets the select back to the first option.
document.formName.one.selectedIndex = 0;
//With jQuery
$('select[name=one]')[0].selectedIndex = 0;