|
|
|
สามารถใช้ formatnumber ร่วมกับ getelement ได้หรือเปล่าครับ |
|
|
|
|
|
|
|
งง-*-
|
|
|
|
|
Date :
2010-06-27 22:04:49 |
By :
asane |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (ASP)
<script type="text/javascript">
//<![CDATA[
function KeyPress(e) {
var keynum;
var keychar;
var numcheck;
if (window.event) // IE
{
keynum = e.keyCode;
}
else if (e.which) // Netscape/Firefox/Opera
{
keynum = e.which;
}
keychar = String.fromCharCode(keynum);
numcheck = /\d|[\b]|[\.]/;
return numcheck.test(keychar);
}
function KeyUp(txtBox) {
var source = txtBox.value.replace(/,/gi, '').split('.', 2);
var output = '';
var decimal = '';
var count = 0;
if (source[0].length > 3) {
while (source[0].length > 1 && source[0].substring(0, 1) == '0') source[0] = source[0].substring(1);
count = (source[0].length % 3 == 0) ? 3 : source[0].length % 3;
output = source[0].substring(0, count);
for (var i = 0; i < (source[0].length / 3) - 1; i++) output += ',' + source[0].substring((i * 3) + count, (i * 3) + 3 + count);
if (source[1] != null) decimal = '.' + source[1];
}
else {
source[0] = (source[0] == '' && txtBox.value.substring(0, 1) == '.') ? '0' : source[0];
output = (source[0].length > 1 && source[0].substring(0, 1) == '0') ? source[0].replace(/0/i, '') : source[0];
decimal = (source[1] != null) ? '.' + source[1] : '';
}
txtBox.value = output + decimal;
}
//]]>
</script>
<input name="TextBox1" type="text" id="TextBox1" onkeypress="javascript:return KeyPress(event);" onkeyup="javascript:KeyUp(this);" />
|
|
|
|
|
Date :
2010-06-27 22:11:40 |
By :
tungman |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากครับ^^
|
|
|
|
|
Date :
2010-06-28 02:12:12 |
By :
asane |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้ร่วมกันไม่ได้จริงด้วย ผมเป็นคอมผมก็คง จะงงเหมือนกัน จะยัดอะไรนักก็ไม่รู้
แต่ก็ยังดีที่เรามี Javascript ช่วย ^^
ขอบคุณมากครับ
|
|
|
|
|
Date :
2010-06-28 02:17:51 |
By :
asane |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|