58 lines
1.2 KiB
HTML
58 lines
1.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Document</title>
|
|
</head>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
border: none;
|
|
outline: none;}
|
|
|
|
.main{
|
|
width: 400px;
|
|
height:300px;
|
|
border: 1px solid #000;
|
|
position: relative;
|
|
}
|
|
.main textarea {
|
|
width: 100%;
|
|
height: 100%;
|
|
resize: none;
|
|
}
|
|
|
|
|
|
</style>
|
|
|
|
<body>
|
|
<div class="main">
|
|
<textarea name="" id="" ></textarea>
|
|
<span>100/100</span>
|
|
</div>
|
|
|
|
</body>
|
|
<script>
|
|
var message=document.querySelector("textarea")
|
|
tips =document.querySelector(".main.span")
|
|
total=100
|
|
message. oninput =function(){
|
|
var sy = total - message.value.length;
|
|
if(sy<=0){
|
|
tips.innerText = "已达限制"
|
|
tips.classList.replace("hui", "red")
|
|
message.value = message.value.substring(0, 100)
|
|
}else{
|
|
tips.innerText = `100/${sy}`
|
|
tips.classList.replace("red", "hui")
|
|
|
|
}
|
|
|
|
}
|
|
</script>
|
|
|
|
</html> |