gpt4 book ai didi

javascript - jQuery 找到所有按钮并单击

转载 作者:行者123 更新时间:2023-12-03 11:19:06 25 4
gpt4 key购买 nike

我有一个 javascript 片段,它为我添加到单独上传的文件呈现单独的按钮,如下所示

data.context = $('<button name=uploadFile/>').text('Start Individual Upload')
.appendTo(document.body)
.click(function () {
// code to do individual upload (removed for brevity)
});

如果我选择了 3 个文件,渲染标记将如下所示:

<button name="uploadFile">Start Upload</button>
<button name="uploadFile">Start Upload</button>
<button name="uploadFile">Start Upload</button>

如果我单独单击每个按钮,将调用单击处理程序并上传文件。

我现在想要尝试的是一个“上传所有”按钮,我可以将其添加到我的html中,然后在该“上传所有”按钮上添加一个单击处理程序函数,该函数触发每个上传按钮的单击处理程序(即 - 模仿用户单击每个开始上传按钮?

 <input id="uploadAllFiles" type="button">

$('#uploadAllFiles').on("click", function () {
// not sure what to do here to find all buttons with name = uploadFile and trigger clicking them
});

最佳答案

当您单击 uploadAllFiles 按钮时,请单击每个名为 uploadFile 的按钮

$('#uploadAllFiles').on("click", function() {
//This will click each of the buttons with the
//attribute name set to "uploadFile"
$('button[name="uploadFile"]').click()
});

关于javascript - jQuery 找到所有按钮并单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27204523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com