2014-09-24 2 views
0

У меня есть выпадающий список, и я хочу использовать jquery, чтобы увидеть, выбрано ли в нем выбранное поле. <option id="id" class="class" selected >Option</option> есть метод в jquery, который сделает это, чтобы вернуть true или false в зависимости от что это такоеjquery selected dropdown return true или false

+2

, так как опция имеет идентификатор вы можете '$ («# идентификатор») является («: выбирается»).' –

+0

Расширьте свой вопрос, пожалуйста ... – Hackerman

+0

Arun P Johny это именно то, что я хотел, может вы можете написать это как ответ – user3956534

ответ

0

ou может использовать jQuery для проверки всего на выбранном элементе.

// get the selected item 

// note: this is getting the parent 'select' element first and then finding 
//  the selected option within the selects child elements 

var selectedOption = $('select').find('option:selected'); 

// you could also use a selector to find a specific select within the page, e.g., 
var select = $('select.my-select'); // this will find a select with a class attribute of 'my-select' 

// get the text from it 
var text = selectedOption.text(); 

// get the html from it 
var html = selectedOption.html(); 

// get an attribute from it 
var classNames = selectedOption.attr('class'); 
var id = selectedOption.attr('id'); 
Смежные вопросы