Javascript 表单提交onClick函数不在选择菜单中创建选项

Javascript 表单提交onClick函数不在选择菜单中创建选项,javascript,jquery,html,twitter-bootstrap,Javascript,Jquery,Html,Twitter Bootstrap,函数getOption(){ var select=document.getElementById(“动态选择”); 如果(选择.options.length>0){ var option=select.options[select.selectedIndex]; 警报(“文本:+option.Text+”\n值:+option.value); }否则{ window.alert(“选择框为空”); } } 函数addOption(){ var select=document.getElemen

函数getOption(){ var select=document.getElementById(“动态选择”); 如果(选择.options.length>0){ var option=select.options[select.selectedIndex]; 警报(“文本:+option.Text+”\n值:+option.value); }否则{ window.alert(“选择框为空”); } } 函数addOption(){ var select=document.getElementById(“动态选择”); select.options[select.options.length]=新选项('new Element','0',false,false); }

放置自动完成的地址表单
.pac集装箱{
z指数:10000!重要;
}
运输方式
交付给*
选择配送
添加送货地址
&时代;
添加您的交付详细信息
地址

街道地址 路线 城市 陈述 邮政编码 国家 新增 接近
首先,您使用的是
按钮type=“submit”
它将发回,只需使用
添加新的

其次,
要么从
标记中删除模型,要么在
addOption()
函数中使用
return false

第三,使用jquery
map()
函数收集side
addOption()

检查此代码:

函数getOption(){ var select=document.getElementById(“动态选择”); 如果(选择.options.length>0){ var option=select.options[select.selectedIndex]; 警报(“文本:+option.Text+”\n值:+option.value); }否则{ window.alert(“选择框为空”); } } 函数addOption(){ var select=document.getElementById(“动态选择”); var newListItem=$(“#myModal input”).map(函数(){return$(this.val();}).get(); select.options[select.options.length]=新选项(newListItem,'0',false,false); $('#myModal').modal('toggle'); 返回false; }

运输方式
交付给*
选择配送
添加送货地址
&时代;
添加您的交付详细信息
地址

var select = document.getElementById("dynamic-select");
var option = document.createElement("option"); 
option.text = "your text";
option.value = "your value"