jquery监听表单输入变化-调用函数

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<title>jquery监听input表单输入变化-调用函数</title>
</head>
<body>

 

<div style="border: 1px solid gray; color: orangered; width: 800px; margin: auto;">
<span id="name" style="width: 500px;"></p>
</div>


<input type="text" id="myInput" />


<script>
document.getElementById('myInput').addEventListener('input', function(event) {
console.log(event.target.value); // 输出当前输入框的值
$('#name').append(event.target.value);
});
</script>


</body>
</html>

posted on 2025-07-07 15:20  四季皆春  阅读(5)  评论(0)    收藏  举报

导航