53 lines
1.2 KiB
HTML
53 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>留言</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
textarea {
|
|
resize: none;
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
.main {
|
|
position: relative;
|
|
margin: 10% auto;
|
|
width: 300px;
|
|
height: 200px;
|
|
}
|
|
.main span {
|
|
position: absolute;
|
|
right: 10px;
|
|
bottom: 10px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="main">
|
|
<textarea name="" id="" cols="30" rows="10"></textarea>
|
|
<span class="text">0/30</span>
|
|
</div>
|
|
|
|
</body>
|
|
|
|
<script>
|
|
var input = document.querySelector("textarea")
|
|
var text = document.querySelector(".text")
|
|
|
|
input.oninput = function () {
|
|
if (input.value.length > 30) {
|
|
input.value = input.value.substring(0,30)
|
|
} else {
|
|
text.innerText = `${input.value.length}/30`
|
|
}
|
|
}
|
|
</script>
|
|
|
|
</html> |