我是JavaScript的新手,我需要一些代码的帮助,以便当我从下拉列表中选择一个选项时,会出现一个新窗口或弹出窗口,并选择该项目。
<select name="select12">
<option>- Select -</option>
<option value="volvo">Volvo</option>
<option value="bmw">BMW</option>
<option value="benz">Benz</option>
</select>
<button class="btn btn-normal" type="button" id="sign-in-button6">submit</button>
答案 0 :(得分:1)
此示例生成一个包含所选项目的正版弹出窗口:
<select id="dropdown" name="select12">
<option>- Select -</option>
<option value="volvo">Volvo</option>
<option value="bmw">BMW</option>
<option value="benz">Benz</option>
</select>
<button onclick="myFunction()">Submit</button>
window.myFunction = function() {
var myWindow = window.open("", "", "width=200, height=100");
var dd = document.getElementById("dropdown");
myWindow.document.write(dd.options[dd.selectedIndex].innerHTML);
}
JSFiddle:https://jsfiddle.net/e6yvom80/
答案 1 :(得分:0)
这是你想要实现的目标:
function submitClicked() {
var dropDown = document.getElementsByName('select12')[0];
// Change .innerHTML to .value if you need value instead of text
var selectedValue = dropDown.options[dropDown.selectedIndex].innerHTML;
alert(selectedValue);
}
<form>
<select name="select12">
<option>- Select -</option>
<option value="volvo">Volvo</option>
<option value="bmw">BMW</option>
<option value="benz">Benz</option>
</select>
<input type="submit" onclick="submitClicked();"/>
</form>