前辈:用js验证是否输入的是,某个已定汉字,要求源码中不出现该汉字,请问怎样用utf-8码写入?

前辈:用js验证是否输入的是,某个已定汉字,要求源码中不出现该汉字,请问怎样用utf-8码写入?

问题描述:

 <!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解码为字符

对字符做一个编码处理