返回输入数据练习...登陆

输入数据练习

Peter2019-02-27 12:07:18254

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title></title>

<style type="text/css">

*{margin: 0;padding: 0px;}

.box1{width: 500px;height: 400px;background: pink;margin: 0 auto;}

.box2{width: 200px;height: 30px;font-size: 20px;line-height: 30px;float:right;}

.box2 span{font-size: 25px;}

textarea{width: 498px;height: 200px;background: #ccc;font-size: 20px;}

button{float:right;width: 40px;height: 20px;margin-right: 20px;background: blue;}

</style>

<script type="text/javascript">

var num, txt, x

window.onload = function (){

num = document.getElementById('num')

txt = document.getElementById('txt')

bt = document.getElementById('bt')

txt.onkeyup = function my(){

x = 140-txt.value.length

num.innerHTML = x

if(x>=0){

num.style.color ='red'

} else{

num.style.color= 'blue'

}

}

bt.onclick = function (){

if(x==140){

alert('请输入内容')

txt.foucus()

}else if(x<0){

alert('超出字数')

}else{alert('发布成功')

}

}

my()

}


</script>

</head>

<body>

<div class="box1">

<div class="box2">你还可以输入<span id="num"></span>个数字</div>

<textarea id="txt"></textarea>

<input type="button" value="发布" id="bt">

</div>

</body>

</html>


最新手记推荐

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

全部回复(0)我要回复

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