<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>驗證輸入</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="blank " />
</head>
<body>
<p>請輸入某個簡體漢字。</p>
<input id="cdemo" type="text">
<script>
function cmyFunction()
{
var x=document.getElementById("cdemo").value;
if(x!="學")
//學 utf-8 %E5%AD%A6
// if(x!="%E5%AD%A6") 沒實現屏顯效果 未解決問題
//if(x!="&%E5%AD%A6")
{alert ("GO ON");}
}
</script>
<button type="button" onclick="cmyFunction()">點擊這裡</button>
</body>
</html>
直接對比就好了。。你對比“學”的編碼干嘛?
如果是encodeURIComponent編碼過的字符,先用的decodeURIComponent解碼為字符