Archive

Posts Tagged ‘JavaScript sprintf’

JavaScript sprintf

sprintf trong javascript (giống keyword sprintf trong PHP)

1/ Download code từ link sau:

http://www.diveintojavascript.com/projects/javascript-sprintf
hoặc
http://www.mediafire.com/?hiej4qpiewohgcv

2/ Cách sử dụng:

đặt khối lệnh sau trong thẻ khai báo thực thi ngôn ngữ javascript

var stringURL = "Hay click vao day de tiep tuc";
chú ý:
var hrefLInk = "http://webdesignviet.worddpress.com";
var formatStringURL = sprintf(stringURL, hrefLInk );
//ouput "Hay
click vao day de tiep tuc"

3/ Một vài kiểu dữ liệu

% — print a literal “%” character
b — print an integer as a binary number
c — print an integer as the character with that ASCII value
d — print an integer as a signed decimal number
e — print a float as scientific notation
u — print an integer as an unsigned decimal number
f — print a float as is
o — print an integer as an octal number
s — print a string as is
x — print an integer as a hexadecimal number (lower-case)
X — print an integer as a hexadecimal number (upper-case)

Tham khảo nguần: http://www.diveintojavascript.com/projects/javascript-sprintf

Advertisements
Categories: Scripts Tags: