PDA

Xem đầy đủ chức năng : Thêm dấu đô la và dấu phẩy



JavaScriptBank
21-01-2010, 07:34 PM
Hiệu ứng sẽ thêm kí hiệu đô la và dấu phẩy vào dãy số do người dùng nhập vào.... chi tiết (http://www.javascriptbank.com/currency-format-script.html/vi//) tại JavaScriptBank.com - 2.000+ free JavaScript codes (http://www.javascriptbank.com/)


http://www.javascriptbank.com/javascript.images/utility/currency-format-script.jpg (http://www.javascriptbank.com/javascript/utility/converter/currency-format-script/preview/vi/)
Demo: JavaScript Thêm dấu đô la và dấu phẩy (http://www.javascriptbank.com/currency-format-script.html/vi/)
| JavaScript Currency Format script (http://www.javascriptbank.com/currency-format-script.html)

Cách cài đặt

Bước 1: Copy mã JavaScript bên dưới và dán vào khu vực HEAD trên trang web của bạn
JavaScript

<SCRIPT LANGUAGE="JavaScript">
// Cyanide_7 ([email protected]) | http://www7.ewebcity.com/cyanide7

<!-- Begin
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
// End -->
</script>
<!--
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
-->


Bước 2: Copy mã HTML bên dưới và dán vào khu vực BODY trên trang web của bạn
HTML

<form name=currencyform>
Enter a number then click the button: <input type=text name=input size=10 value="1000434.23">
<input type=button value="Convert" onclick="this.form.input.value=formatCurrency(this.form.inp ut.value);">
<br><br>
or enter a number and click another field: <input type=text name=input2 size=10 value="1000434.23" onBlur="this.value=formatCurrency(this.value);">
</form>
<!--
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
-->




Các hiệu ứng tương tự
- Thêm dấu phẩy vào số (http://www.javascriptbank.com/add-comas-to-numeric-items.html/vi/)
- Thêm dấu phẩy vào dãy số bằng nút (http://www.javascriptbank.com/commas-script.html/vi/)
- Thêm dấu phẩy vào dãy số (http://www.javascriptbank.com/auto-currency-script.html/vi/)
Bạn có thể xem thêm nhiều JavaScript khác về Ứng dụng (http://www.javascriptbank.com/javascript/utility/vi/) và Bộ chuyển đổi (http://www.javascriptbank.com/javascript/utility/converter/vi/)





Trình chơi nhạc giao diện WMP và iPhone 3G (http://www.javascriptbank.com/mp3-player-with-wmp-and-iphone-3g-skin.html/vi/) - JavaScript chạy theo thanh cuộn (http://www.javascriptbank.com/vi=chạy theo thanh cuộn) - JavaScript lấy vị trị trỏ chuột (http://www.javascriptbank.com/forum/hoi-ve-javascript-t180.html)