gpt4 book ai didi

javascript - 如何实用地将下拉列表更改为另一个字段的值

转载 作者:行者123 更新时间:2023-12-03 02:52:31 24 4
gpt4 key购买 nike

我有一个包含国家/地区列表(所有国家/地区)的下拉列表

<select id="Country" onchange="country();">
<option id="3">Japan</option>
<option id="4">Canada</option>
<option id="5">France</option>
<option id="6">Peru</option>
</select>

我有一个模态表单,我想从中获取国家/地区值。

<input id="seachcountry" type="text" class="form-control" name="country">

我编写了一个 JQuery 行来获取从模式表单到页面字段的值,一切都很好,但国家/地区选择字段没有更改值。

$("#seachcountry").val($("#modalform").val()).trigger("chang‌e");

感谢您的建议!

最佳答案

这对你有用:

只需注入(inject) value <input>的至<select> .

我已经为您创建了一个片段。

var Tval = $('#seachcountry').val();

$('#Country').val(Tval);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="Country" onchange="country();">
<option id="3">Japan</option>
<option id="4">Canada</option>
<option id="5">France</option>
<option id="6">Peru</option>
</select>

<input id="seachcountry" type="text" class="form-control" name="country" value="France">

关于javascript - 如何实用地将下拉列表更改为另一个字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47787346/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com