<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/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>
原文地址:https://www.cnblogs.com/zhangwensi/p/10498782.html
时间: 2024-11-13 08:45:31