<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>获取输入框内容示例</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 0 auto;
padding: 20px;
}
.container {
background-color: #f5f5f5;
padding: 20px;
border-radius: 5px;
}
input {
padding: 8px;
width: 100%;
box-sizing: border-box;
margin-bottom: 10px;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
#result {
margin-top: 15px;
padding: 10px;
background-color: #e9e9e9;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="container">
<h2>获取输入框内容示例</h2>
<p>这个示例展示了如何使用JavaScript获取输入框的内容。</p>
<input type="text" id="myInput" placeholder="在这里输入内容...">
<button onclick="getInputValue()">获取输入内容</button>
<div id="result"></div>
</div>
<script>
// 获取输入框内容的函数
function getInputValue() {
// 获取输入框元素
let inputElement = document.getElementById("myInput");
// 获取输入框的值
let inputValue = inputElement.value;
// 显示结果
document.getElementById("result").innerHTML =
"你输入的内容是: <strong>" + inputValue + "</strong>";
}
</script>
<!-- 页面底部信息 -->
<footer style="margin-top: 30px; text-align: center; color: #666;">
</footer>
</body>
</html>
503

被折叠的 条评论
为什么被折叠?



