我这有一段代码:涉及代码安全性,无论输入什么(功能键除外)都显示“*”号,只有当刷新页面时,才能清空内容,当然,可以设置显示样式。问题是我想获得这个层中的值,我试了用隐藏域获取,可是没有效果。所以请大家帮忙看看,有没有好的方法。代码如下:
<!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=gb2312" />
<title>无标题文档</title>
</head>
<script>
function document.onkeydown()                
{         
     document.getElementById("tt").innerText+="*";         
     return false;                      
}
</script>
<body>
<div id="tt" style="border-top:#333 2px solid; border-left:#333 2px solid; border-bottom:#cdcdcd 1px solid; border-right:#cdcdcd 1px solid; width:300px; height:23px; cursor:text;"></div>
</body>
</html>

解决方案 »

  1.   

    你把脚本写到js文件里不就得了
    然后引入js文件调呗  就跟你调类一样
      

  2.   

    呵呵 我之前试过了 不行的
    <script type="text/javascript" language="javascript">
        function document.onkeydown() {
            document.getElementById("tt").innerText += "*";
            return false;
        }
        function getValue() {
            alert(document.getElementById("tt").value);
            document.getElementById("HiddenField1").value = document.getElementById("tt").value;
        }
    </script>
    <body>
        <form id="test" runat="server">
        <asp:HiddenField ID="HiddenField1" runat="server" />
    <div id="tt" style="border-top:#333 2px solid; border-left:#333 2px solid; border-bottom:#cdcdcd 1px solid; border-right:#cdcdcd 1px solid; width:300px; height:23px; cursor:text;"></div>  
        <input id="Hidden1" type="hidden" />
        <input id="Button2" type="button" value="取值" onclick="getValue()"/>
            </form>
    </body>
    这种方式不能获得啊!
      

  3.   

    加个判断就可以了。if(event.keycode=13){}