javascript - 当复选框选中时如何单击不同 div 的标签?

标签 javascript html

当复选框被选中时,

我想触发点击同一tr标签中具有下载功能的标签(按顺序) 点击[开始下载]按钮。

它们在不同的<< td >>标签中,彼此在同一个<< tr >>标签中

如何按顺序触发点击?

我是否需要使用for语句按复选框顺序单击不同div中的元素?

<tr>
  <td id="10Mb.dat"><input type="checkbox" data-url="https://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73751/world.topo.bathy.200407.3x21600x10800.jpg" />File10MB
  </td>
  <td class="test"><a class="checkBtn checkBtn1" id="checkBtn1" onclick="download_file(event, '10Mb.dat')">download</a></td>
</tr>
<tr>
  <td id="100mb.bin"><input type="checkbox" data-url="http://speedtest-ny.turnkeyinternet.net/100mb.bin" />File100MB
  </td>
  <td class="test"><a class="checkBtn checkBtn2" id="checkBtn2" onclick="download_file(event, '100mb.bin')">download</a></td>
</tr>
 <button class="btn btn-primary compress">download start</button>

最佳答案

为您的复选框提供一个 css 类。

$('.checkboxclass').click(function(){
    $(this).closest('td').parents('tr').find('.checkBtn').click();
}

要使用按钮进行检查,请循环访问表中选中的复选框,

$("table.test 
input:checkbox:checked").parents('tr').find("input[name$='.checkBtn']")
.each(function(){
   download(link); //write the code to download file
}

关于javascript - 当复选框选中时如何单击不同 div 的标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54858715/

相关文章:

javascript - Node + 远程登录 + OS X

javascript - 如何访问 Colorbox 中的 JavaScript/jQuery 函数?我还没有得到满意的答复

javascript - 使用 Moment.js 从 UTC 格式化时间

javascript - 返回在函数内部不起作用(快照)

javascript - Jquery 和 AJAX 脚本在后台运行 PHP 脚本以避免任何刷新

javascript - 如何在 while 循环中为每个 div 创建一个 ID 并使用 JQuery 发出警报

python - 使用 Bootstrap 选项卡将 JSON 数据从数据库显示到 django 模板

html - 可以为成对的 div 设置相等的高度,但前提是浏览器宽度为 960 或更宽?

html - CSS Focus 无法影响其他元素

javascript - 如何分享弹窗的url?