获取输入框内容示例

<!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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值