Iterating a selectlist to highlight an item, highlights each item in turn

I have the following jQuery method that iterates over a selectlist containing a number of options. I want to hihlight the first line that has a match for some text typed by the user into a textbox named MMDCriteria. Currently the code is selecting and highlighting each item in turn until it gets to the end of the list. $("#MMDCriteria").bind('keypress', function(e) { var code = (e.keyCode ? e.keyCode : e.which); if(code == 13) { //Enter keycode var criteria = $(this).val().toUpperCase(); alert(""); $('select#MMD > option').each(function() { var optionValue = $(this).text().toUpperCase(); alert(optionValue.substring(0, optionValue.indexOf(criteria))); if(optionValue.substring(0, optionValue.indexOf(criteria)) > -1) { $(this).attr('selected', 'selected'); } }); } }); I have only just started using jQuery so excuse the verboseness.

以上就是Iterating a selectlist to highlight an item, highlights each item in turn的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏