【发布时间】:2018-09-17 00:51:55
【问题描述】:
我正在尝试制作一个包含大陆、地区、国家、省、市、区和村庄的链式下拉列表,但我被困在国家/地区。
我的下拉列表要求我使用数据库中的 id 来链接所有下拉列表,因此要获取文本名称,我通常使用此方法:
国家:
<select name="loc_country" class="loc_country loc5" id="loc_country" onchange="javacript: var valor2 = this.options[selectedIndex].text; document.getElementById('loc_country_real').value = valor2;">
<option value="0">-Select-</option>
</select>
<input type="text" id="loc_country_real" name="loc_country_real">
但是这次这种方法不起作用,所以我尝试了另一种方法:
<select name="loc_country" class="loc_country loc5" id="loc_country">
<option value="0">-Select-</option>
</select>
<input type="text" id="loc_country_real" name="loc_country_real">
和js:
$("#continent").change(function () {
$("#loc_country_real").val($('#loc_country').text());
});
并希望当我的 id="continent" 选择框发生变化时,该值会更新。
而且该方法也失败了,因为“loc_country_real”中给出的值与选择框“loc_country”不匹配
(例如:当我在大陆选择框上选择欧洲时,loc_country 选择框会给我一个列表欧洲国家,但“loc_country_real”中的值将来自国家/地区的亚洲)
我需要使“loc_country”和“loc_country_real”中的文本匹配,但我不知道该怎么做,请帮忙。
【问题讨论】:
-
具体是什么问题?您的最终陈述表明您只需要 2 个下拉菜单即可包含相同的值?
-
试图将文本从“loc_country”选择框复制到“loc_country”文本框