html中ss标签,如何用 cspanclassss 选择器选中如下 html 中的 span 标签

=""="-"=""aria-="true"="radio__inputis-checked"//省略里面的内容/spanspanclass="radio__label"备选项1/span/labellabelrole="radio"spanclass="radio__input"//省略里面的内容/spanspanclass="radio__label"备选项3/span/labellabelrole="radio"spanclass="radio__input"//省略里面的内容/spanspanclass="radio__label"备选项3/span/label/div

如上html结构,现在想用css选择器实现选中当前被checked项中的文本span标签,即上面备选项1、备选项2、备选项3对应3个span

当前被checked的项会在给当前lable标签添加一个aria-checked="true"属性,所以我现在可以通过label[aria-checked="true"]选中被checked的lable

需要选中的span是lable的第二个子元素,用nth-child(n)不行,nth-child(n)是选择属于其父元素的第n个子元素的每个标签元素

直接通过span[class="radio__label"]试了也不能选中所有span

通过jsdocument.getElementsByClassName("el-radio__label")倒是可以选中所有的span标签,css选择器如何实现呢?

客串前端,名次或术语用的不对的还请各位见谅!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果需要在去除 HTML 标签的同时,保留上下标,可以使用 Apache POI 库的 RichTextString 类来实现。具体的代码如下: ``` // 导入 Apache POI 库 import org.apache.poi.ss.usermodel.*; // 导入 Jsoup 库 import org.jsoup.Jsoup; import org.jsoup.nodes.Document; // 去除 HTML 标签并保留上下标 String htmlText = "<td><p>java<sub>2</sub></p><td>"; Document document = Jsoup.parse(htmlText); String plainText = document.text(); Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet("Sheet1"); Row row = sheet.createRow(0); Cell cell = row.createCell(0); // 创建带上下标的 RichTextString 对象 RichTextString richTextString = new XSSFRichTextString(plainText); int subIndex = htmlText.indexOf("<sub>"); while (subIndex >= 0) { int endIndex = htmlText.indexOf("</sub>", subIndex); richTextString.applyFont(subIndex, endIndex + 6, createSubScriptFont(workbook)); subIndex = htmlText.indexOf("<sub>", endIndex); } int supIndex = htmlText.indexOf("<sup>"); while (supIndex >= 0) { int endIndex = htmlText.indexOf("</sup>", supIndex); richTextString.applyFont(supIndex, endIndex + 6, createSupScriptFont(workbook)); supIndex = htmlText.indexOf("<sup>", endIndex); } // 在单元格设置 RichTextString 对象 cell.setCellValue(richTextString); // 写入 Excel 文件 FileOutputStream outputStream = new FileOutputStream("test.xlsx"); workbook.write(outputStream); outputStream.close(); workbook.close(); ``` 在上面的代码,我们先将带有 HTML 标签的文本转换成 Document 对象,然后调用 text() 方法去除 HTML 标签,得到纯文本。接着,我们创建了一个带上下标的 RichTextString 对象,并且使用 applyFont() 方法设置上下标的格式。最后,将 RichTextString 对象写入到单元格,再将数据写入到 Excel 文件。 在上面的代码,我们使用了 createSubScriptFont() 和 createSupScriptFont() 方法来创建下标和上标的字体。这两个方法的代码如下: ``` private static Font createSubScriptFont(Workbook workbook) { Font font = workbook.createFont(); font.setTypeOffset(Font.SS_SUB); return font; } private static Font createSupScriptFont(Workbook workbook) { Font font = workbook.createFont(); font.setTypeOffset(Font.SS_SUPER); return font; } ``` 这两个方法都是用来创建字体的,一个是下标字体,一个是上标字体。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值