Skip to content

Instantly share code, notes, and snippets.

@niwaringo
Created January 26, 2012 15:29
Show Gist options
  • Save niwaringo/1683281 to your computer and use it in GitHub Desktop.
Save niwaringo/1683281 to your computer and use it in GitHub Desktop.
jQuery Plugin fhconvert data-attr ver
(function($) {
$.fn.fhconvert = function() {
$(this).each(function() {
var $this = $(this);
//data属性を取得する。
var $dataAttr = $this.data('fhconvert');
//data属性がない場合は抜ける
if(typeof($dataAttr) === 'undefined') {
return true;
}
//data属性から値を取得する。
var fhconvertType = $dataAttr.type;
var settings = $.extend({
'jaCode':true,
'space':true,
'convSet':'object'
}, $this.data('fhconvert').option);
// hfconvertに渡す
$this.val(FHConvert[fhconvertType]($this.val(), settings));
});
return this;
};
}(jQuery));
フォーカスが外れると全角になる。
<input class="fhconvert" type="text" data-fhconvert='{"type": "htof"}' />
<br />
フォーカスが外れると半角になる。
<input class="fhconvert" type="text" data-fhconvert='{"type": "ftoh"}' />
<br />
フォーカスが外れるとカナになる。
<input class="fhconvert" type="text" data-fhconvert='{"type": "hgtokk"}' />
<script type="text/javascript">
$(function() {
$('.fhconvert').blur(function() {
$(this).fhconvert();
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment