[英]Selected Country / State From Dynamic Dropdown List
我在代码中使用了这个“国家/地区”动态选择:
这是演示页面: http : //bdhacker.sourceforge.net/javascript/countries/
但是,不幸的是,当我创建设置/成员个人资料页面时,需要显示所选国家和州,以便用户可以看到他们已经选择的内容,我不能只是将用户选择的内容作为“值”。
即使选择了一个国家和州,这也是我在页面来源上看到的内容:
Select Country: <select onchange="print_state('state',this.selectedIndex);" id="country" name ="country"></select>
City/District/State: <select name ="state" id ="state"></select>
如何将价值放在那? 因为我确实是这样的:
Select Country:
<select onchange="print_state('state',this.selectedIndex);" id="country" name ="country" value="Indonesia"></select>
City/District/State: <select name ="state" id ="state"></select>
但我仍然看不到选择的国家。 谢谢!
试试这个解决方案http://jsfiddle.net/yDAmR/
print_country("country");
$('#country').val('Indonesia');
print_state('state',$('#country')[0].selectedIndex);
您看到美国在其他国家/地区指定州的原因是,JavaScript缺少州/省/州下拉列表的重置。 在拆分列表数组之前,只需在JS文件中添加“ option_str.length = 0; //清除列表”即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.