我有一些包含两个单选按钮的HTML。根据选择的单选按钮,我想下载两个文件中的一个。我怎么能这样做?
这是我到目前为止所尝试的内容:
<head>
<script type="text/javascript">
function downloadAddin(){
document.getElementById("bit32");
if (document.getElementById("bit32").checked) {
document.location.href="ECSSetup32.exe";
} else {
document.location.href="ECSSetup64.exe";
}
}
</script>
</head>
<form>
<p><input type="radio" id="bit32" name="arch" checked>Windows 32-bit
<br><input type="radio" id="bit64" name="arch">Windows 64-bit
<p>
<button type="submit" onclick="downloadAddin()"id="download_button"
style="background-color: #0078FF; padding: 1%; color: #ffffff; border:1px
solid; border-radius:10px; font-size:75%">Accept and Download</button>
</form>
我希望用户能够选择单选按钮,按“同意并下载”按钮,然后获取他们请求的两个.exe文件之一。有什么想法吗?
答案 0 :(得分:1)
一个简单的JS代码就可以完成这项工作。
<input type="radio" name="download" id="x86"/>winrar x86 <br />
<input type="radio" name="download" id="x64"/>winrar x64 <br />
<input type="button" id="download" value="download"/>
var radio_x86 = document.getElementById('x86');
var radio_x64 = document.getElementById('x64');
var button = document.getElementById('download');
button.onclick = downloadFile;
function downloadFile() {
if(radio_x86.checked) {
window.open("http://www.rarlab.com/rar/wrar500.exe");
}else if(radio_x64.checked) {
window.open("http://www.rarlab.com/rar/winrar-x64-500.exe");
} else {
alert("Please check one of the options first.");
}
}
编辑: Fiddle: your own code
除非您使用post / get。
<form>
标记包装输入元素