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="support@mail.com" selected>Support</option>
<option value="bill@mail.com">Billing</option>
<option value="sales@mail.com">Sales</option>
</select>
<span id="mail_info">
<input type="text" name="email" class="form-control" value="support@mail.com" 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="support@mail.com" selected>Support</option>
<option value="bill@mail.com">Billing</option>
<option value="sales@mail.com">Sales</option>
</select>
<span id="mail_info">
<input type="text" name="email" class="form-control" value="support@mail.com" readonly>
</span>
添加回答
举报