Created
February 10, 2014 03:15
-
-
Save naoaki011/8909779 to your computer and use it in GitHub Desktop.
JS
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
<div id="contents_main_inner"> | |
<div> | |
<select id="hoge"> | |
<option value="1">オプション1</option> | |
<option value="2">オプション2</option> | |
<option value="3">オプション3</option> | |
<option value="4">オプション4</option> | |
<option value="5">オプション5</option> | |
<option value="6">オプション6</option> | |
<option value="7">オプション7</option> | |
<option value="8">オプション8</option> | |
<option value="9">オプション9</option> | |
<option value="10">オプション10</option> | |
<option value="11">オプション11</option> | |
</select> | |
<input type="text" id="search_text" value="" /> | |
<input type="button" id="search_button" value="検索" /> | |
</div> | |
<div id="search_multi"></div> | |
<script type="text/javascript"> | |
var search_items = [ | |
{ | |
id: 1, | |
kanji: '漢字名A', | |
hiragana: 'オプション1' | |
},{ | |
id: 2, | |
kanji: '漢字名B', | |
hiragana: 'オプション2' | |
},{ | |
id: 3, | |
kanji: '漢字名C', | |
hiragana: 'オプション3' | |
},{ | |
id: 4, | |
kanji: '漢字名D', | |
hiragana: 'オプション4' | |
},{ | |
id: 5, | |
kanji: '漢字名E', | |
hiragana: 'オプション5' | |
},{ | |
id: 6, | |
kanji: '漢字名F', | |
hiragana: 'オプション6' | |
},{ | |
id: 7, | |
kanji: '漢字名G', | |
hiragana: 'オプション7' | |
},{ | |
id: 8, | |
kanji: '漢字名H', | |
hiragana: 'オプション8' | |
},{ | |
id: 9, | |
kanji: '漢字名I', | |
hiragana: 'オプション9' | |
},{ | |
id: 10, | |
kanji: '漢字名J', | |
hiragana: 'オプション10' | |
},{ | |
id: 11, | |
kanji: '漢字名K', | |
hiragana: 'オプション11' | |
} | |
]; | |
jQuery(function(){ | |
jQuery('#search_button').click(function(){ | |
// jQuery('#search_multi').html(''); | |
var val = jQuery('#search_text').val(); | |
if(!val){ | |
alert('検索テキストを入力して下さい'); | |
return false; | |
} | |
for(var i = 0; i < search_items.length; i++){ | |
var item = search_items[i]; | |
var kanji = item.kanji; | |
var hiragana = item.hiragana; | |
var hit = false; | |
if(kanji.match(val)){ | |
hit = true; | |
}else if(hiragana.match(val)){ | |
hit = true; | |
} | |
if(hit){ | |
jQuery('#hoge').val(item.id); | |
} | |
} | |
}) | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment