Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在html中添加车辆选择下拉菜单_Javascript_Html_Css_Drop Down Menu - Fatal编程技术网

Javascript 在html中添加车辆选择下拉菜单

Javascript 在html中添加车辆选择下拉菜单,javascript,html,css,drop-down-menu,Javascript,Html,Css,Drop Down Menu,我想添加两个下拉菜单。一个用于汽车品牌,另一个用于汽车型号。 我已经做了汽车品牌,但它只显示了4辆车,这是马鲁蒂斯威夫特,马鲁蒂阿尔托,马鲁蒂瓦格纳。我有一个品牌和型号的excel文件,我想将其添加到此列表中。 总共有210辆汽车。我不想单独打印,因为这需要很多时间。有没有较短的方法 这是我写的:- <div class="wrap-input100"> <span class="label-input100">Car Make:</

我想添加两个下拉菜单。一个用于汽车品牌,另一个用于汽车型号。 我已经做了汽车品牌,但它只显示了4辆车,这是马鲁蒂斯威夫特,马鲁蒂阿尔托,马鲁蒂瓦格纳。我有一个品牌和型号的excel文件,我想将其添加到此列表中。 总共有210辆汽车。我不想单独打印,因为这需要很多时间。有没有较短的方法

这是我写的:-

<div class="wrap-input100">
                <span class="label-input100">Car Make:</span>
                <!-- <input class="input100" type="text" name="Make" placeholder="Enter Make of Your Car"> -->
                <form action="/action_page.php">
                <select name="cars">
                  <option value="select">select</option>
                  <option value="Maruti,Swift">Maruti,Swift</option>
                  <option value="Maruti,WagonR">Maruti,WagonR</option>
                  <option value="Maruti,Swift">Maruti,Swift Dzire</option>
                  <option value="Maruti,Alto">Maruti,Alto</option>
                </select>
                <span class="focus-input100"></span>
            </div>

汽车制造:
选择
马鲁蒂,斯威夫特
马鲁蒂,瓦贡
马鲁蒂,斯威夫特·泽尔
阿尔托马鲁蒂

从任何在线工具将excel转换为json,该工具将为您提供对象数组: (谷歌“excel到json在线”你会发现很多工具)

您可以根据您的json更改我的代码的js对象键

HTML和Javascript

<!DOCTYPE html>
<html>

  <head>



  </head>

  <body>
    <h1>Hello Plunker!</h1>
     <select name="cars" id="cars">
                  </select>
     <script>
        let json = [
    {
        "Brand": "Maruti",
        "Model": "Swift"
    },
    {
        "Brand": "Maruti",
        "Model": "Desire"
    },
    {
        "Brand": "Maruti",
        "Model": "WagonR"
    },
    {
        "Brand": "Maruti",
        "Model": "Ritz"
    },
    {
        "Brand": "Maruti",
        "Model": "Zen"
    },
    {
        "Brand": "Maruti",
        "Model": "Alto"
    }
];
dropDown = document.getElementById('cars') ;
function myFunction(item, index) { 
  console.log(item.Brand,item.Model)
  dropDown.innerHTML = dropDown.innerHTML + "<option value='"+item.Brand + ' ' + item.Model +"'>"+item.Brand +' ' +  item.Model+"</option>"
}

json.forEach(myFunction)


      </script>
  </body>

</html>

你好,普朗克!
让json=[
{
“品牌”:“马鲁蒂”,
“模型”:“Swift”
},
{
“品牌”:“马鲁蒂”,
“模型”:“欲望”
},
{
“品牌”:“马鲁蒂”,
“型号”:“瓦格纳”
},
{
“品牌”:“马鲁蒂”,
“模型”:“丽思”
},
{
“品牌”:“马鲁蒂”,
“模型”:“禅”
},
{
“品牌”:“马鲁蒂”,
“型号”:“Alto”
}
];
dropDown=document.getElementById('cars');
函数myFunction(项,索引){
console.log(item.Brand,item.Model)
dropDown.innerHTML=dropDown.innerHTML+“”+item.Brand+“”+item.Model+“”
}
forEach(myFunction)

是的,您可以使用apache poi编写java程序来读取excel,然后将响应发送到ui,并使用中的数据创建下拉列表response@brk它将比复制和粘贴更长。Pranteek Singh您可以将列复制到纯文本文件中,然后使用您喜爱的文本编辑器中的regexp对其进行更改。您可以将这些汽车添加到后端,并使用ajax调用获取它们,这将使您的代码在需要添加或删除汽车时具有灵活性。