yubinbango.js で、住所が取得できた瞬間をイベントで検知したいんですが、うまく行きません。
jQuery で $('input[name=prefecture]').on('change') などとしてもダメです。
HTML
1<form class="h-adr"> 2 <span class="p-country-name" style="display:none;">Japan</span> 3 <input type="text" name="zip" class="p-postal-code"> 4 <input type="text" name="prefecture" class="p-region"> 5 <input type="text" name="city" class="p-locality"> 6 <input type="text" name="address" class="p-street-address p-extended-address"> 7 <input type="text" name="city_code"> 8</form>
JavaScript
1$(function(){ 2 $('input[name=zip]').on('keyup', function(){ 3 // $('input[name=city]').on('change', function(){ が理想 4 if ($('input[name=city]').val()) { 5 // 取得した瞬間には反応しない 6 $.post('/get/city/code', { // 市区町村コードを取得するPHPプログラム呼び出し 7 prefecture: $('input[name=prefecture]').val(), 8 city: $('input[name=city]').val() 9 }, 'json').done(function(r){ 10 $('input[name=city_code]').val(r.code); 11 }).fail(function(){ 12 alert('取得失敗'); 13 }); 14 } 15 }); 16});
という上記のコードもうまく動作しませんでした。
$('input[name=zip]').on('blur') ならば
取得後の値を拾うことができるのですが、
タイミングが「取得した瞬間」ではないのでちょっと希望とは違います。
どうすればその瞬間を捉えることができますでしょうか。
どなたかご存じの方、よろしくお願いいたします。