如何选择 id 包含特定子字符串的所有元素? [英] How to select all elements whose id contains a particular substring?

查看:39
本文介绍了如何选择 id 包含特定子字符串的所有元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择 id 包含特定子字符串的所有元素.例如对于这些:

<div id="foowoohoo"><div><div id="foodoowoo"><div><div id="soobootoo"><div>

我想获取 ID 中包含 foo 的元素.

解决方案

首先,您的标记似乎已损坏.一旦你像这样修复它:

<div id="foobootoo"></div><div id="foowoohoo"></div><div id="foodoowoo"></div><div id="soobootoo"></div>

如果你使用这个 xpath,你只会得到前三个节点://div[contains(@id, 'foo')].

I want to select all elements whose id contains a particular substring. For example for these:

<div id="foobootoo"><div>
<div id="foowoohoo"><div>
<div id="foodoowoo"><div>
<div id="soobootoo"><div>

I want to get elements that has foo in the id.

解决方案

First of all your markup seems broken. Once you fix it like this:

<div id="foobootoo"></div>
<div id="foowoohoo"></div>
<div id="foodoowoo"></div>
<div id="soobootoo"></div>

if you use this xpath you will get only the first three nodes: //div[contains(@id, 'foo')].

这篇关于如何选择 id 包含特定子字符串的所有元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆