如何在新窗口中从外部按钮的下拉列表中访问所选链接?
<select id="atheist">
<option value="http://google.com"></option>
<option value="http://yahoo.com"></option
</select>
var select = document.getElementById("select");
select.addEventListener("change",function() {
var win = window.open(this.value, "_blank");
win.focus();
},false);
因此,我只需点击一下按钮就可以从下拉列表中访问/转到所选链接。你能帮忙吗?
答案 0 :(得分:0)
<强> HTML 强>
<select id="atheist">
<option value="http://google.com">Google</option>
<option value="http://yahoo.com">Yahoo</option>
</select>
<input id="downloadbtn" type="button" value="download" />
<强> JS 强>
function openLink(){
var e = document.getElementById("atheist").value;
console.log(e);
var win = window.open(e, "_blank");
win.focus();
}
window.onload=function(){
var downloadbtn = document.getElementById("downloadbtn");
downloadbtn.onclick=openLink;
};
<强> JS 强>
function openLink(){
var e = document.getElementById("atheist").value;
var win = window.open(e, "_blank");
win.focus();
}
window.onload=function(){
var downloadbtn = document.getElementById("downloadbtn");
downloadbtn.addEventListener("click", openLink, false);
};
这类似于以下内容:inputing text in textbox
答案 1 :(得分:-2)
我想在这里你想要选择网站,并希望在点击downlad按钮后打开该网站。
<强> HTML 强>
<select id="select">
<option value="http://google.com">google</option>
<option value="http://yahoo.com">yahoo</option>
</select>
<button id="myButton">Download</button>
<强> JS 强>
var button = document.getElementById("myButton");
button.addEventListener("click", function() {
var select = document.getElementById('select');
var win = window.open(select.options[select.selectedIndex].value, "_blank");
win.focus();
},false);