3 に答える
3
試す
$('select.color option:contains(white)').prop('selected','selected');
選択したオプションが「白」であるすべての要素を選択します。
$('select.color option:contains(white):selected').parent('select');
正確な値に一致
$('select.color option:contains(white):selected').each(function(){
if($(this).text() == 'white'){
$(this).parent('select').css('color','blue');
}
});
于 2013-09-13T06:49:42.463 に答える
2
これを試して。
$("select.color option:selected:contains(white)").parent();
これにより、白で始まるテキストを持つすべての選択要素が取得されます
注: whitesmokeにも一致します
編集:次のコードは正確な値を提供します。
var requiredelements = $("select.color option:selected").filter(
function()
{
return ( $.trim($(this).text())=== 'white')
}).parent('select');
alert(requiredelements.length);
于 2013-09-13T07:11:23.637 に答える
1
$('select.color').each(function(index, element) {
if($(this).find('option:selected').text()=='white') {
// do something with select box which contains white text or use array to get all contents
}
});
于 2013-09-13T07:27:11.977 に答える