Javascript 如何在我的网站上获得国家列表

Javascript 如何在我的网站上获得国家列表,javascript,php,jquery,Javascript,Php,Jquery,我正试图找到一种方法来显示所有国家的下拉列表。是否有php或jquery中的短代码可以在我的网页上获取国家列表?提前谢谢。在struts2中您可以得到它- e、 g 在jQuery中,您必须通过ajax调用获取列表并对其进行迭代 e、 g, $.ajax({ url:'rcmidAuditTrail.action', 键入:“GET”, async:false, 数据类型:“json”, 错误:函数(数据){ console.log('error'); }, 成功:功能(列表){ var h

我正试图找到一种方法来显示所有国家的下拉列表。是否有php或jquery中的短代码可以在我的网页上获取国家列表?提前谢谢。

在struts2中您可以得到它- e、 g


在jQuery中,您必须通过ajax调用获取列表并对其进行迭代 e、 g,

$.ajax({
url:'rcmidAuditTrail.action',
键入:“GET”,
async:false,
数据类型:“json”,
错误:函数(数据){
console.log('error');
},
成功:功能(列表){
var html=''
$。每个(列表、函数(i、值){
html+=''+值+'';
});
$('dropdownId').html(html);
}
});
我建议使用:

它以不同的格式(文本、JSON、PHP…)为您提供国家列表

或者,如果您只需要快速的HTML列表,请转到:

您可以直接将这些值复制粘贴到任意位置,也可以调用该页面。

我使用npm包

import countries from "countries-list";
获取有关国家的广泛信息:

console.log(countries.countries);
将为您提供:

{
   AD: {
      name: "Andorra"
      native: "Andorra"
      phone: "376"
      continent: "EU"
      capital: "Andorra la Vella"
      currency: "EUR"
      languages: ["ca"]
      emoji: "Following on from Ruslan Kazakov.

If you're using typescript and the countries-list npm package, I found that the following made the typescript compiler happy if you were looking to get a list of country names for a dropdown.

const countryNames = Object.values(countries.countries)
  .map((item) => item.name))
  .sort();
{
广告:{
姓名:“安道尔”
本地人:“安道尔”
电话:376
欧洲大陆:“欧盟”
首都:“安道尔拉维拉”
货币:“欧元”
语言:[“ca”]
表情符号:“从后面开始

如果您使用的是typescript和npm软件包,我发现如果您希望获得下拉列表中的国家名称,下面的内容会让typescript编译器感到高兴

const countryNames=Object.values(countries.countries)
.map((项)=>item.name))
.sort();

请显示您当前的尝试(如果有)。非常感谢kamal。kamal我需要在数据库中插入所有国家,因为我必须在php中使用它吗?
console.log(countries.countries);
{
   AD: {
      name: "Andorra"
      native: "Andorra"
      phone: "376"
      continent: "EU"
      capital: "Andorra la Vella"
      currency: "EUR"
      languages: ["ca"]
      emoji: "Following on from Ruslan Kazakov.

If you're using typescript and the countries-list npm package, I found that the following made the typescript compiler happy if you were looking to get a list of country names for a dropdown.

const countryNames = Object.values(countries.countries)
  .map((item) => item.name))
  .sort();