[JQuery] textbox focus on offÀ϶§ ¼ýÀÚ ÄÞ¸¶ º¸¿©ÁÖ±â |
|
|
 |
5³â Àü |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" language="javascript">
// Numeric only control handler
jQuery.fn.ForceNumericOnly =
function() {
return this.each(function() {
$(this).keydown(function(e) {
var key = e.charCode || e.keyCode || 0;
// allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
return (
key == 8 ||
key == 9 ||
key == 46 ||
(key >= 37 && key <= 40) ||
(key >= 48 && key <= 57) ||
(key >= 96 && key <= 105)
);
});
// Æ÷Ä¿½º ³ª°¥¶§ ÄÞ¸¶Ã³¸®
$(this).focusout(function() { $(this).val($(this).val().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")); });
// Æ÷Ä¿½º µé¾î¿Ã¶§ ÄÞ¸¶Ã³¸®
$(this).focusin(function() { $(this).val($(this).val().replace(/\,/g, '')); });
// Å° ´·¶À»¶§ ÄÞ¸¶Ã³¸®
$(this).keyup(function() {
$(this).val($(this).val().replace(/,/g, ''));
$(this).val($(this).val().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
});
})
};
window.onload=function(){
$('.num').ForceNumericOnly();
}
</script>
</HEAD>
<BODY>
<input type="text" class="num" name="number_1"/>
<input type="text" class="num" name="number_2"/>
<input type="text" class="num" name="number_3"/>
</BODY>
</HTML>
|
|
̵̧ : 227 |
̵̧
¸ñ·Ï
|
|