限制输入字数JS

复制代码
    <tr>
            <th><b>说明内容:</b><span id="content">(500字以内)</span></th>
        </tr>
        <tr>
            <td><input type="text" name="content" value="{$data['content']}"  class="easyui-textbox" data-options="required:false,multiline:true" style="width:700px; height:350px;"></td>
        </tr>

        <script type="text/javascript">
                $("input[name=content]").textbox({
                 onChange:function(newValue,oldValue){
                     if(newValue.length>5){
                     // $(".easyui-linkbutton").attr('disabled','false');//禁用a标签中的onclick事件
                       // $('.easyui-linkbutton').removeAttr('onclick');//去掉a标签中的onclick事件
                       $("span#content").html('输入的内容已超过5字!');
                       $("span#content").css('color','red');      
                     }else{   
                         $("span#content").html('');  
                      return newValue;

                       }
                     }
                })        
        </script>



——————————————————————————————————————————————————
<tr>
        <td>
        <b>说明内容:</b>
            <span>(限500字以内,您还可以输入字数:<input name="termLen" value="500" style=" font-size:15pt; color:red; border:0; text-align:center; width: 40px"  readonly />字)</span>
        </td>
    </tr>

    <tr>       
        <td colspan="2" align="center">  
            <textarea id="content" name="content" style="width: 90%; height: 300px; margin-top:5px;" onKeyPress="checkLen(this)" onKeyUp="checkLen(this)" onChange="checkLen(this)">{$data['content']}</textarea> 
        </td>
    </tr> 



    <script type="text/javascript">   
            function checkLen(term){        
                document.all.termLen.value=500-term.value.length;        
                    if (document.all.termLen.value<=0){          
                            term.value=term.value.substring(0,500);         
                        }        
             } 
    </script>    

    <tr>
        <th style="text-align:center;"><a class="easyui-linkbutton" href="JavaScript:void(0);" onclick="From_Submit('PointsSign')" data-options="iconCls:'iconfont icon-add'"><span style="font-size:14px; font-weight:600;">保存</span></a></th>
    </tr>
复制代码

 

posted @   吴青伶  阅读(1034)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示