Javascript 根据所选的单选按钮,如何下载多个文件中的一个?
我有一些HTML,包括两个单选按钮。根据选择的单选按钮,我想下载两个文件中的一个。我该怎么做 以下是我迄今为止所尝试的:Javascript 根据所选的单选按钮,如何下载多个文件中的一个?,javascript,html,radio-button,Javascript,Html,Radio Button,我有一些HTML,包括两个单选按钮。根据选择的单选按钮,我想下载两个文件中的一个。我该怎么做 以下是我迄今为止所尝试的: <head> <script type="text/javascript"> function downloadAddin(){ document.getElementById("bit32"); if (document.getElementById("bit32").c
<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>
函数下载addin(){
document.getElementById(“bit32”);
if(document.getElementById(“bit32”).已选中){
document.location.href=“ECSSetup32.exe”;
}否则{
document.location.href=“ECSSetup64.exe”;
}
}
Windows 32位
Windows 64位
接受并下载
我希望用户能够选择一个单选按钮,按下“同意并下载”按钮,然后获取他们请求的两个.exe文件之一。有什么想法吗?一个简单的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"/>
编辑:除非您使用的是post/get,否则您不需要用
标记来包装您的输入元素。仅供参考,如果您不展示您尝试过的内容并询问您遇到的特定问题,您的问题将受到负面影响。@Nick刚刚说了什么。然后,再次寻找这样的东西:?好的,我已经更新了问题;对不起,如果不清楚的话。我只是注意到一些驴子用-4票把我的帖子搞糟了。如果我看不到任何回复,我会重新发布。@akinuri谢谢,这正是我需要的!我怎么能相信你呢?再次谢谢你,阿基努里。downloadFil()中的两行是我要找的。
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.");
}
}