使用cheerio 显示非隐藏内容 <td><span v-show="data.FndDrc=='01'">入账</span> <span v-show="data.FndDrc=='04'" style="display: none;">退汇</span> <span v-show="!(data.FndDrc=='04'||data.FndDrc=='01')" style="display: none;">待客户确认</span> </td>
时间: 2024-02-13 09:06:28 浏览: 22
你可以使用以下代码使用 cheerio 来显示非隐藏内容:
```javascript
const cheerio = require('cheerio');
const html = `<td><span v-show="data.FndDrc=='01'">入账</span> <span v-show="data.FndDrc=='04'" style="display: none;">退汇</span> <span v-show="!(data.FndDrc=='04'||data.FndDrc=='01')" style="display: none;">待客户确认</span> </td>`;
const $ = cheerio.load(html);
$('span:not([style*="display:none"])').each((i, el) => {
console.log($(el).text());
});
```
这段代码将输出非隐藏的 span 标签中的文本内容:`入账`。解释一下,`:not([style*="display:none"])` 表示选择器不包含样式属性中包含 `display:none` 的元素,也就是非隐藏的元素。
相关问题
使用cheerio 显示内容 <td><span v-show="data.FndDrc=='01'">入账</span> <span v-show="data.FndDrc=='04'" style="display: none;">退汇</span> <span v-show="!(data.FndDrc=='04'||data.FndDrc=='01')" style="display: none;">待客户确认</span> </td>
你可以使用以下代码使用 cheerio 来显示这段 HTML 内容:
```javascript
const cheerio = require('cheerio');
const html = `<td><span v-show="data.FndDrc=='01'">入账</span> <span v-show="data.FndDrc=='04'" style="display: none;">退汇</span> <span v-show="!(data.FndDrc=='04'||data.FndDrc=='01')" style="display: none;">待客户确认</span> </td>`;
const $ = cheerio.load(html);
$('span').each((i, el) => {
console.log($(el).text());
});
```
这段代码将输出三个 span 标签中的文本内容:`入账`、`退汇` 和 `待客户确认`。
使用cheerio 转换 以下代码 <td><span v-show="data.FndDrc==\'01\'">入账</span> <span v-show="data.FndDrc==\'04\'" style="display: none;">退汇</span> <span v-show="!(data.FndDrc==\'04\'||data.FndDrc==\'01\')" style="display: none;">待客户确认</span> </td> <td class="v-binding">受理成功</td>
可以使用Cheerio将这段代码转换成HTML字符串。首先,需要安装Cheerio模块,可以在命令行中使用以下命令进行安装:
```
npm install cheerio
```
然后,在Node.js中可以使用以下代码将该代码段转换成HTML字符串:
```javascript
const cheerio = require('cheerio');
const html = '<td><span v-show="data.FndDrc==\'01\'">入账</span> <span v-show="data.FndDrc==\'04\'" style="display: none;">退汇</span> <span v-show="!(data.FndDrc==\'04\'||data.FndDrc==\'01\')" style="display: none;">待客户确认</span> </td> <td class="v-binding">受理成功</td>';
const $ = cheerio.load(html);
const td1 = $('td').eq(0).html();
const td2 = $('td').eq(1).html();
const result = `<td>${td1}</td><td class="v-binding">${td2}</td>`;
console.log(result);
```
运行后,将输出以下HTML字符串:
```html
<td><span v-show="data.FndDrc=='01'">入账</span></td><td class="v-binding">受理成功</td>
```
注意,Cheerio中的html()方法将返回匹配选择器的第一个元素的HTML字符串。在这个例子中,我们可以使用eq()方法获取第一个和第二个td元素的内容,并将它们拼接成一个新的HTML字符串。