根据不同 div 中后面的文本检查复选框?
有没有办法根据复选框后面的文本来检查复选框?工作中的应用程序需要我根据后面的文本检查很多框。似乎可以通过编程方式完成,但这绝对超出了我有限的知识范围
这是页面的模糊片段。
<tr>
<td><span title="original"><input id="a0" type="checkbox" name="orginal_a0" value="0"><label for="a0">
<div class="List">
<div>
<div>Default Thing</div>
</div>
</div>
</label></span></td>
</tr>
<tr>
<td><span title="original"><input id="a1" type="checkbox" name="original_a1" value="1"><label for="a1">
<div class="List">
<div>
<div>New Thing</div>
</div>
</div>
</label></span></td>
</tr
我知道我可以根据输入的 ID 或名称,但不幸的是,它们无法帮助确定我是否应该选中该框。重要的是框后面的文本。如果我可以做到这一点,它会选中任何以“New”或任何其他文本开头的框,但也不选中以“Default”开头的框。因此,在上面的示例中,我会选中第二个框,而不选中第一个框。在应用程序中,它通常会选中 50-75 个框,但会留下类似数量的未选中框。理想情况下,我可以直接在控制台中输入或制作成书签。
这可能吗?
Is there a way to check checkboxes based on text that follows them? An App at work that requires me to check ALOT of boxes depending on the text that follows. Seems like it could be done programmatically, but it's definitely beyond my limited knowledge
Here's an obscured snippet of the page.
<tr>
<td><span title="original"><input id="a0" type="checkbox" name="orginal_a0" value="0"><label for="a0">
<div class="List">
<div>
<div>Default Thing</div>
</div>
</div>
</label></span></td>
</tr>
<tr>
<td><span title="original"><input id="a1" type="checkbox" name="original_a1" value="1"><label for="a1">
<div class="List">
<div>
<div>New Thing</div>
</div>
</div>
</label></span></td>
</tr
I know I could based on the input id or name, but unfortunately they don't help identify if I should or should not check the box. It's the text that follows the box that's important. If iIcould make it so it would check any box that begin with "New" or any other text, but also not check the ones that begin with "Default". So in the example above I'd check the 2nd box and not check the 1st one. In the app it's generally checking 50-75 boxes but leaving a similar amount unchecked. Ideally it would be something I could just type into the console or make into a bookmarklet.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以循环遍历所有单元格,检查文本是否不以
default
开头,并将checked
状态设置为input
请注意,最好不要将
div
元素嵌套在span
或label
等内联元素中You could loop over all the cells, check if the text doesn't begin with
default
and set thechecked
state to theinput
As a side note it's better to not nest a
div
element inside an inline element like aspan
or alabel
此示例循环遍历所有复选框并获取下一个元素,假定该元素是标签。如果指示的 div 不是以“默认”开头,它将选中该框。
This example loops through all the checkboxes and grabs the next element, which is assumed to be the label. If the div indicated doesn't begin with "Default" it will check the box.