//
you're reading...
Codes, Fun4Fi, Internet, Javascript, Others, Tuts & Tips

Mẹo Nhỏ: Đảo Chữ Lộn Ngược Với Javascript

<SCRIPT>function flip() {
var result = flipString(document.form_flip.original_text.value.toLowerCase());
document.form_flip.flipped_text.value = result;
}

function flipString(aString) {
var last = aString.length - 1;
var result = new Array(aString.length)
for (var i = last; i >= 0; --i) {
var c = aString.charAt(i)
var r = flipTable[c]
result[last - i] = r ? r : c
}
return result.join('')
}

var flipTable = {
a : '\u0250',
b : 'q',
c : '\u0254', 
d : 'p',
e : '\u01DD',
f : '\u025F', 
g : '\u0183',
h : '\u0265',
i : '\u0131', 
j : '\u027E',
k : '\u029E',
//l : '\u0283',
m : '\u026F',
n : 'u',
r : '\u0279',
t : '\u0287',
v : '\u028C',
w : '\u028D',
y : '\u028E',
'.' : '\u02D9',
'[' : ']',
'(' : ')',
'{' : '}',
'?' : '\u00BF', 
'!' : '\u00A1',
"\'" : ',',
'<' : '>',
'_' : '\u203E',
'\u203F' : '\u2040',
'\u2045' : '\u2046',
'\u2234' : '\u2235',
'\r' : '\n' 
}

for (i in flipTable) {
flipTable[flipTable] = i
}
</SCRIPT>

<FORM name=form_flip>
	Original Text: <BR/>
	<TEXTAREA onkeyup=flip() name=original_text rows=5 cols=50></TEXTAREA> 
	<INPUT onclick=flip() type=button value="Đảo ngược"> <BR/>
	Flipped Text: <BR/>
	<TEXTAREA name=flipped_text rows=5 cols=50></TEXTAREA> 
</FORM>

~Sưu Tầm~

Advertisements

Discussion

One thought on “Mẹo Nhỏ: Đảo Chữ Lộn Ngược Với Javascript

  1. Just call the function in an HTML element and it would flip the text in it.

    Posted by Monex Investigation | 16.12.2010, 22:25

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: