惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MongoDB | Blog
MongoDB | Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - Franky
博客园 - 聂微东
V
Visual Studio Blog
I
InfoQ
罗磊的独立博客
Security Latest
Security Latest
G
Google Developers Blog
博客园_首页
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
D
DataBreaches.Net
PCI Perspectives
PCI Perspectives
Forbes - Security
Forbes - Security
P
Proofpoint News Feed
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Know Your Adversary
Know Your Adversary
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Recent Commits to openclaw:main
Recent Commits to openclaw:main
The Cloudflare Blog
AWS News Blog
AWS News Blog
Latest news
Latest news
T
Tailwind CSS Blog
P
Palo Alto Networks Blog
Hugging Face - Blog
Hugging Face - Blog
云风的 BLOG
云风的 BLOG
Cyberwarzone
Cyberwarzone
T
The Exploit Database - CXSecurity.com
WordPress大学
WordPress大学
Recorded Future
Recorded Future
A
Arctic Wolf
V
Vulnerabilities – Threatpost
Security Archives - TechRepublic
Security Archives - TechRepublic
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
月光博客
月光博客
有赞技术团队
有赞技术团队
P
Privacy & Cybersecurity Law Blog
Scott Helme
Scott Helme
美团技术团队
Hacker News - Newest:
Hacker News - Newest: "LLM"
Jina AI
Jina AI
N
News and Events Feed by Topic
Attack and Defense Labs
Attack and Defense Labs

博客园 - asdsd

js收藏 - asdsd - 博客园 ArrayList最佳使用建议 右下角弹出消息 数据岛与分页 滚动条的设置 SQL中CONVERT转化函数的用法 js实现自动全屏幕 - asdsd - 博客园 迅速返回页面顶部代码 - asdsd - 博客园 图示元素的clientTop、offsetTop、offsetHeight等属性 新浪天气-模拟 揭开正则表达式 javascript中获取radiobuttonlist选中值 开发时碰到的问题以及心得经验 经常用到的javaScript技术 一劳永逸 让你与IE弹出窗口彻底告别 随机排1-100数字 判断一个对象是否存在 用C#制作新闻阅读器(电脑报2005年3月14日 第10期) 遮挡的问题
用js限制用户输入字节个数 - asdsd - 博客园
asdsd · 2007-07-04 · via 博客园 - asdsd

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title>New Document </title>

    <script language="JavaScript">
    <!--
    function CutStrLength(str,Ilength)
    {
        var tmp=0;
        var len=0;
        var okLen=0
        for(var i=0;i<Ilength;i++)
        {
            if(str.charCodeAt(i)>255)
                tmp+=2
            else
                len+=1
            okLen+=1
            if(tmp+len==Ilength)
            {
                return (str.substring(0,okLen));
                break;
            }
            if(tmp+len>Ilength)
            {
                return (str.substring(0,okLen-1)+"");
                break;
            }
        }
    }
    function checkFieldLength(fieldName,fieldDesc,fieldLength)
    {
        var str=document.getElementById(fieldName).value;
        var theLen=0;
        var teststr='';
        for(i=0;i<str.length;i++)
        {
            teststr=str.charAt(i);
            if(str.charCodeAt(i)>255)
            theLen=theLen+2;
            else
            theLen=theLen+1;
        }
        document.getElementById('showMsg').innerText=theLen;
        if(theLen>fieldLength)
        {
            document.getElementById('showMsg').innerText=fieldDesc;
            //alert(fieldDesc+" 的字段长度超过规定长度!");
            //document.getElementById(fieldName).focus();
            document.getElementById(fieldName).value=CutStrLength(str,fieldLength);
            return false;
        }
        else
        {
            return true;
        }
    }
    //-->
    </script>

</head>
<body>
    <form method="POST" action="">
        <textarea id="testArea" name="testArea" rows="3" cols="22" onkeyup="checkFieldLength('testArea', '超过允许输入的字符个数', 20);"
            onchange="checkFieldLength('testArea', '超过允许输入的字符个数', 20);"></textarea>
        <div id="testInfo">
            已经输入:<span id="showMsg"></span></div>
    </form>
</body>
</html>