javascript - 如果单击多个复选框,则打开多个选项卡
问题描述
我正在设计一个 chrome 扩展,用户可以选择检查任意数量的框,这些框将加载与他们选择的选择相对应的不同网页。
到目前为止,我的复选框的 html 代码是:
<input type="checkbox" name="selection" value="google"
id="google" >
<input type="checkbox" name="selection" value="yahoo"
id="yahoo" >
<input type="checkbox" name="selection" value="msn"
id="msn" >
我尝试使用的JS是这样的:
function redirect()
{
if(document.getElementById("google").checked == true) .
window.location.href = 'https://www.google.com';
else if(document.getElementById("yahoo").checked==true)
window.location.href = 'https://www.yahoo.com;
else if(document.getElementById("msn").checked == true)
window.location.href = 'https://www.msn.com;'
}
如果我选择了一个选项,则站点加载正确,但如果选中了多个,则不会将所有站点加载到每个选中的复选框。如何更改代码,以便如果选中多个复选框,该复选框的每个站点都会加载?
解决方案
if (document.getElementById("google").checked == true)
window.open('https://www.google.com');
else if (document.getElementById("yahoo").checked == true)
window.open('https://www.yahoo.com');
else if (document.getElementById("msn").checked == true)
window.open('https://www.msn.com');
推荐阅读
- xamarin.forms - Xamarin Forms Entry 更改阿拉伯语的流向问题
- r - “缺少参数‘模式’” - 在调用 readRDS() 后出现在每个命令之后
- selenium - Selenium side runner 在多个浏览器上并行运行测试
- c++ - 有没有办法根据我是否获得单个或多个模板参数来声明类型别名?最好没有专业
- graphviz - 按等级排列子集群
- math - 模加法器输出显示没有变化
- php - 如何解决托管网站的此错误消息
- flutter - 如何为 Flutter Desktop Windows 应用设置发布应用图标
- php - 为什么“sudo pcmanfm”会破坏 php 函数 move_uploaded_file()?
- python - 如何在 discord.User cog 中添加角色层次结构?