-
-
Save NKid/382cdd941b4d485bfebe to your computer and use it in GitHub Desktop.
Lazy Option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findKeyword(event) { | |
var strKeyword = prompt('Input the Keyword what you want to search.'); | |
var opts = this.options; | |
var matchIndex = []; | |
for(var i = 0; i < opts.length; i++) { | |
if(opts[i].text.indexOf(strKeyword) != -1) matchIndex.push(i); | |
} | |
switch(matchIndex.length) { | |
case 0: | |
alert('Not found.'); | |
break; | |
case 1: | |
this.options[matchIndex[0]].selected = true; | |
break; | |
default: | |
var tmp = 'Found too many keywords.\nPlz choose below options.\n'; | |
for(var i = 0; i < matchIndex.length; i++) { | |
tmp += '[' + i + '] ' + this.options[matchIndex[i]].text + '\n'; | |
} | |
var index = prompt(tmp); | |
this.options[matchIndex[index]].selected = true; | |
} | |
} | |
var selectEles = document.getElementsByTagName('select'); | |
for(var i = 0; i < selectEles.length; i++) | |
selectEles[i].addEventListener('focus', findKeyword, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment