Created
January 26, 2012 15:29
-
-
Save niwaringo/1683281 to your computer and use it in GitHub Desktop.
jQuery Plugin fhconvert data-attr ver
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($) { | |
$.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)); |
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
フォーカスが外れると全角になる。 | |
<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