2 回答

TA貢獻1878條經驗 獲得超4個贊
獲取input并設置的值select
function getMailtype(value) {
document.querySelector("#mail_info input").value = value;
}
<select class="form-control" id="mail_type" name="email_to" onChange="getMailtype(this.value)" required>
<option value="[email protected]" selected>Support</option>
<option value="[email protected]">Billing</option>
<option value="[email protected]">Sales</option>
</select>
<span id="mail_info">
<input type="text" name="email" class="form-control" value="[email protected]" readonly>
</span>

TA貢獻2011條經驗 獲得超2個贊
const getMailtype = (target) => {
$("#mail_info > input[name='email'")[0].value = target.value;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select class="form-control" id="mail_type" name="email_to" onChange="getMailtype(this)" required>
<option value="[email protected]" selected>Support</option>
<option value="[email protected]">Billing</option>
<option value="[email protected]">Sales</option>
</select>
<span id="mail_info">
<input type="text" name="email" class="form-control" value="[email protected]" readonly>
</span>
添加回答
舉報