p{
color: #0086B3;
}
.wb{
outline: none;
border: 1px solid orange;
width: 500px;
height: 200px;
padding: 0;
text-align: top;
}
.box{
position: relative;
width: 500px;
height: 220px;
}
span{
position: absolute;
right: 0;
top: 0;
color: #808080;
}
有什么新鲜事相告诉大家?
// var count=0;
// $('.wb').keypress(function(ev){
// // console.log(ev.keyCode)
// if ((ev.keyCode >= 48 && ev.keyCode <= 57) || (ev.keyCode >= 65 && ev.keyCode <= 90) || (ev.keyCode >= 97 && ev.keyCode <= 122)){
// count+=1;
// }
// console.log(count)
// $('.wb').on('input',function(){
// var vals=$('.wb').val();
// var chars=0;
// for(var i=0;i
// if(vals[i].match(/[^\x00-\xff]/ig)!=null){
// chars+=1;
// }
// console.log(chars)
// }
// }
// )
// })
$('.wb').on('input',function(){
var count=0;
var vals=$('.wb').val();
console.log(vals)
if(vals.length==0){
$('span').text(null);
}
for (var i=0;i
if(vals[i].match(/[^\x00-\xff]/ig)!=null)//全角
count+=1;
else{
count+=0.5;
}
$('span').text('已输入'+Math.ceil(count)+'个字');
if(count>=140){
$('span').css('color','orange')
}
else{
$('span').css('color','#808080')
}
}
// console.log(this.value);
// $('span').text('已输入'+this.value.length)
// $('span').text($(this).val(this.value))
// console.log($('.wb').val())
})
一键复制
编辑
Web IDE
原始数据
按行查看
历史