具有国家/地区代码的国家/地区的分割方法 [英] Split Method for country with country code

查看:117
本文介绍了具有国家/地区代码的国家/地区的分割方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含世界所有国家的数组
例如我带了3个国家.

I have an array which contains all countries of world
for example i have taken 3 countries.

var option_str = document.getElementById('country');
country_array[0]="USA|India|Australia";

var mySplitResult = country_array[0].split("|");

 for (var i = 0; i < mySplitResult.length; i++) {
	        option_str.options[i] = new Option(mySplitResult[i],mySplitResult[i]);
	    }


我已经使用拆分方法来获取每个国家/地区

我的prvios来源是


I have used split method to get each country

my prvios source was

<select name ="country" id = "country"></select>



执行完此查询后
输出是



after excute this query
out put is

<select name ="country" id = "country">
<option>USA</option>
<option>India</option>
<option>Australia</option>
</select>



但我想做这样的事情:



But I want to do some thing like this:

<select name ="country" id = "country">
<option value="US">USA</option>
<option value="IN">India</option>
<option value="AU">Australia</option>
</select>



代码是什么,或者我可以在其中用我的代码进行修改的代码,就像上面的代码一样
但是您可以在array



What is the code or where i can modify with my code which will see like the above
but u can use country code in array

推荐答案

中尝试使用国家/地区代码
Try this
option_str.options[i] = new Option(mySplitResult[i],mySplitResult[i].substring(0,2).toUpperCase());


这篇关于具有国家/地区代码的国家/地区的分割方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆