随select动,将value值显示在后面的input里

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<title>Document</title>
</head>
<body>
<input type="text" id="txt">
<select id="test">
<option value="option-1">option-1</option>
<option value="option-2">option-2</option>
<option value="option-3">option-3</option>
</select>

<script>


$(document).ready(function() {
document.getElementById("txt").value = document.getElementById("test").value;
document.getElementById("test").onchange = function() {
document.getElementById("txt").value = this.value;
}
});
</script>

</body>
</html>

猜你喜欢

转载自www.cnblogs.com/zhangwensi/p/10498782.html