返回控制微博文字字......登陆

控制微博文字字数js代码

Binbin(斌斌老师)2019-01-29 19:57:37253

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>weibo</title>

<style type="text/css">

body{font-size:12px;}

.clear{clear:both;}

.left{float: left; margin-left: 15px; margin-top:5px;font-size:14px;}

</style>

<script type="text/javascript">

var text,number,margin

window.onload=function (){

text=document.getElementById('text')

number=document.getElementById('number')

bt=document.getElementById('bt')

text.onkeyup=function aa(){

m=140-text.value.length

if(m<0){

number.style.color="red"

}else{

number.style.color="#888"

}

number.innerHTML=m

}

bt.onclick=function(){

if(m==140){

alert("你还没有输入内容呢!")

text.focus()

}else if(m<0){

alert("你输入的字符超过140字啦!请减少字数!")

text.focus()

}else{

alert("发布成功啦!")

}

}

}

</script>

</head>

<body>

<div style="width: 580px; margin: 0 auto;">

<div style="float: left;font-size:16px;">有什么新鲜事想告诉大家?</div>

<div style="float: right;color:grey;">已输入<span id="number">140</span>字</div>

<div></div>

<textarea id="text" style="width: 580px; height: 80px;font-size: 16px;" onkeyup="aa()"></textarea>

<span>※ 表情</span>

<span>※ 图片</span>

<span>※ 视频</span>

<span>※ 话题</span>

<span>※ 头条文章</span>

<input type="submit" id="bt" style="float:right;font-size:14px;color:#fff;background-color: #ff7f4d;padding:5px 20px;">

<div></div>

</div>

</body>

</html>

最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送