html:

<div class="ellipsis">
夜空中最亮的星/请指引我走出去/夜空中最亮的星 是否知道/那曾与我同心的身影 如今在哪里/夜空中最亮的星 是否在意/
</div>

js:

$(document).ready(function(){
//限制字符个数
$(".ellipsis").each(function(){
var maxwidth=39;
if($(this).text().length>maxwidth){
$(this).text($(this).text().substring(0,maxwidth));
$(this).html($(this).html()+'…');
alert();
}
});
});

另一种:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>输入字符限制</title>
<script type="text/javascript" src="js/jquery-1.11.0.js"></script>
<style>
.tucao_dl {
width: 518px;
overflow: hidden;
}
.tucao_dl dt {
clear: both;
margin-top: 5px;
}
.tucao_dl dt textarea {
background: none;
border: none;
border: 1px solid #ddd;
width: 510px;
height: 135px;
line-height: 24px;
padding-top: 3px;
font-size: 14px;
color: #999;
font-family: '微软雅黑';
resize: none;
}
.tucao_dl dt i {
color: #ff6600;
}
.tucao_dl dd {
float: left;
color: #999;
font-family: '微软雅黑';
font-size: 14px;
}
.tucao_dl dd i {
color: #ff6600;
}
.focusing{background-color: rgba(22,219,10,0.5);} </style>
</head>
<body> <dl class="tucao_dl" >
<dt>
<textarea id="OtherText" title="http://www.cnblogs.com/Han39/。" class="feedbackT" onkeyup="maxlength(this)" onfocus="editAdvice()"></textarea>
</dt>
<dd>您还可以输入<i>200</i>字</dd>
</dl> </body>
<script>
$(document).ready(function(){
$('#OtherText').each(function(){
$(this).val($(this).attr('title'));
}).focus(function(){
if(this.value == $(this).attr('title')){
$(this).val('').addClass('focusing');
}; }).blur(function(){
if(this.value == ''){
$(this).val($(this).attr('title')).removeClass('focusing');
};
}); });
function maxlength(obj){;
var num = $(obj).val().length;
if(200-num>=0){
$('.tucao_dl dd').find('i').text(200-num);
}
obj.value = obj.value.slice(0, 200);
}
function editAdvice(){
var advice=removeAllSpace($("#OtherText").val());
var title=removeAllSpace($("#OtherText").attr("title"));
if(advice==null ||advice.length<=0 || advice ==title){
$("#OtherText").text("");
} }
</script>
</html>

js实现限制容器中字符个数的更多相关文章

  1. Python2018-字符串中字符个数统计

    1 编写程序,完成以下要求: 统计字符串中,各个字符的个数 比如:"hello world" 字符串统计的结果为: h:1 e:1 l:3 o:2 d:1 r:1 w:1 prin ...

  2. python统计字符串中字符个数

    str = "xxx" result = {} for i in set(str):#set将字符串转为集合对象,用于去重,减少计算量 result[i] = str.count( ...

  3. 学c语言做练习之​统计文件中字符的个数

    统计文件中字符的个数(采用命令行参数) #include<stdio.h> #include<stdlib.h> int main(int argc, char *argv[] ...

  4. js中找string中重复项最多的字符个数

    // split():字符串中的方法,把字符串转成数组. // sort():数组中的排序方法,按照ACALL码进行排序. // join():数组中的方法,把数组转换为字符串 function de ...

  5. js实现查找字符串中最多的字符的个数

    用hash table实现.key是字符,value是字符个数. var hashTable={}; var str="fjsdeiuwidshjfhjsksghfjhsjjskalsk&q ...

  6. JS正则表达式获取字符串中特定字符

    JS正则表达式获取字符串中得特定字符,通过replace的回调函数获取. 实现的效果:在字符串中abcdefgname='test'sddfhskshjsfsjdfps中获取name的值test  实 ...

  7. oracle查找某个字符在字符串中的个数的技巧

    Oracle没有提供查找某个字符在字符串中出现次数的函数,当遇到这样的需求的时候,我们只能使用另外的方法去实现. 简单的思路就是,假设有个字符串str,然后里面有n个[a]字符,当把这n个[a]字符去 ...

  8. 设在起始地址为STRING的存储空间存放了一个字符串(该串已存放在内存中,无需输入,且串长不超过99),统计字符串中字符“A”的个数,并将结果显示在屏幕上。

    问题 设在起始地址为STRING的存储空间存放了一个字符串(该串已存放在内存中,无需输入,且串长不超过99),统计字符串中字符"A"的个数,并将结果显示在屏幕上. 代码 data ...

  9. js:重复输出字符串中字符

    复习了 重复输出一个字符串后, 重复输出一个字符串是 比如给定 str:abc  num:3 要求输出 abcabcabc 文章链接:https://www.cnblogs.com/mobu/p/98 ...

随机推荐

  1. 线程池(4)-参数-RejectedExecutionHandler

    1.介绍 当线程池线程数大于最大线程数(maximumPoolSize)时,多余的任务,程序应该按照什么拒绝策略处理. 2.拒绝策略4个 AbortPolicy:丢弃任务,并抛出RejectedExe ...

  2. fluent-动网格-动态层

    模型算例来源:http://blog.sina.com.cn/s/blog_599d8faa0100w4uj.html ​原视频下载地址:http://yunpan.cn/cujM2FxLuGdLK ...

  3. Rancher2.3.2部署Kubenetes Dashboard

    首先进入到集群中的System命令空间,因为kubenetes dashboard是给整个集群使用的,并不是默认的Default命名空间使用的 Default命名空间,是默认的命名空间,也是在部署其他 ...

  4. NPVariant -js传递给NPAPI插件参数在firefox和chrome需要采用不同的获取方式

    原帖地址:http://blog.sina.com.cn/s/blog_4c6631790102wd1o.html 整数参数 typedef struct _NPVariant { NPVariant ...

  5. End-To-End Memory Networks

    End-To-End Memory Networks 2019-05-20 14:37:35 Paper:https://papers.nips.cc/paper/5846-end-to-end-me ...

  6. Visual C++2010的使用

    Tools->Settings>Rest... 还原所有设置 运行程序:"D:\Program Files\VCExpress\Install\Microsoft Visual ...

  7. 【JDBC】使用properties连Oracle数据库,使用DatabaseMetaData获取字段的注释

    简单的打铁代码如下: package com.hy.propertyConn; import java.sql.Connection; import java.sql.DatabaseMetaData ...

  8. SQLite与MySQL区别

    原文链接:https://blog.csdn.net/zbw1185/article/details/47975965简单来说,SQLITE功能简约,小型化,追求最大磁盘效率:MYSQL功能全面,综合 ...

  9. SpringMVC 集成 jackson,日志格式报错:org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from String value

    org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from Str ...

  10. 关于PHP7的CURL上传文件

    CULR 部分 $url = 'http://localhost/test/curlUploadFile/upload.php'; //处理上传的php文件,根据情况修改 $path='ftp.txt ...