<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
click the text field, why it does NOT alert 153 ?<br />
<input type="text" value="™" onclick="alert(this.value.charCodeAt(0));" />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
click the text field, why it does NOT alert 153 ?<br />
<input type="text" value="™" onclick="alert(this.value.charCodeAt(0));" />
</body>
</html>
返回一个整数,代表指定位置上字符的 Unicode 编码。而 ™ 是实体字符代码,并非 Unicode 编码!因此结果肯定不一样滴!