我想找到" CAT"在下拉列表中,下拉列表的值为[" Cat"," Rat"," Mat"]因此我无法通过文本和我查找没有ID" CAT"通过id找到。有什么建议吗?
编辑:小写()将改变" CAT"对猫?但我的下拉有#34; Cat"
答案 0 :(得分:2)
尝试比较值lowercase:
if(myvalue.toLowerCase() === ddl[i].toLowerCase()) {
//...
}
答案 1 :(得分:1)
有点晚了,基本上是Mysteryos回答的是用jsFiddle跟进它。
此函数将返回选项:
function Find(searchContent)
{
var options = $('#dropDown option');
var foundOption;
$.each(options, function (key, value)
{
value = $(value);
if(value.html().toLowerCase() == searchContent.toLowerCase())
{
foundOption = value;
}
});
return foundOption;
}
请参阅以下工作示例:http://jsfiddle.net/7fWxZ/
答案 2 :(得分:0)
检查出来:
HTML代码:
<select id="ats">
<option>Cat</option>
<option>Rat</option>
<option>Mat</option>
</select>
jQuery代码:
function findmyat(comparetext){
$('#ats option').each(function(){
if ($(this).val().toLowerCase()==comparetext.toLowerCase()){
//found the option i was looking for, do what i want
alert($(this).val()+' has been found');
}
}
}