当前位置: 首页 > wzjs >正文

万能设计导航深圳seo博客

万能设计导航,深圳seo博客,丽江网络推广公司,淘宝客导购网站下面写的是根据后端返回的html 提取我需要的标签和字 将他们单独添加样式 后端返回的数据 大概类似于<h1>2024年“双11”购物节网络零售监测报告</h1><p>表1 “双11” 期间网络零售热销品类TOP10</p> function checkfun(newList){if (newList) {let …

下面写的是根据后端返回的html 提取我需要的标签和字 将他们单独添加样式

后端返回的数据 大概类似于'<h1>2024年“双11”购物节网络零售监测报告</h1><p>表1 “双11” 期间网络零售热销品类TOP10</p>'

function checkfun(newList){if (newList) {let processedAnswer = newList// 这个是判断如果是h2标签里面只有前言这两字的时候就添加class.replace(    /<h2>(前言)<\/h2>/gs, '<h2><span class="titleclass">$1</span></h2>'// 这个是判断如果是h2标签里面只有报告说明这两字的时候就添加class).replace(/<h2>(报告说明)<\/h2>/gs,'<h2><span class="titleclass">$1</span></h2>'// 这个是判断如果是如果包含表1,图1等的时候就添加class).replace(/((?:表|图)\d+.*?)(?=(?:<p>|<\/p>|<h2>|<h3>|<li>|<\/li>|$))/gs,'<span class="picture">$1</span>')// 这个是判断如果是如果注的时候就添加class.replace(/((?:注)\d+.*?)(?=(?:<p>|<\/p>|<h2>|<h3>|<li>|<\/li>|$))/gs,'<span class="pour">$1</span>')// 添加表格处理逻辑  --- 这个是我根据标准的table格式进行添加classconst doc = parseHTML(processedAnswer);const tables = doc.querySelectorAll('table');tables.forEach((table) => {// 判断是否是table是否只有一个表头const thead = table.querySelector('thead');const theadLength = thead?.rows[0]?.cells.length || 0;if (theadLength === 1) {table.classList.add('single-header');}// 判断表身里面的数据 是否是数字const tbody = table.querySelector('tbody');tbody?.querySelectorAll('td').forEach((td) => {if (isStringNumber(td.textContent)) {td.classList.add('single-cell');}});// 检查表头是否包含“排名”字段  -- 并且排名这个字段必须在第一位const headers = table.querySelectorAll('thead th:first-child');  const rankIndex = Array.from(headers).findIndex(header => header.textContent.trim() == '排名');  // 如果找到排名列,为所有对应单元格添加样式if (rankIndex !== -1) {// 获取所有行数据const rows = table.querySelectorAll('tbody tr');rows.forEach(row => {const cells = row.querySelectorAll('td');if (cells.length > rankIndex) {cells[rankIndex].classList.add('rank-column');}});}});// 获取到所有的p标签和li标签 判断里面是否有数字和英文 如果有的话将他们单独添加classconst pElements = doc.querySelectorAll('p, li');pElements.forEach(p => {const tempDiv = document.createElement('div');tempDiv.innerHTML = p.innerHTML;const walker = document.createTreeWalker(tempDiv, NodeFilter.SHOW_TEXT);let node;while ((node = walker.nextNode())) {const parent = node.parentNode;const text = node.textContent;let lastIndex = 0;// 改进后的正则表达式const numberRegex = /(-?\d+(?:\.\d+)?|[a-zA-Z']+)/g;let numberMatch;while ((numberMatch = numberRegex.exec(text)) !== null) {const span = document.createElement('span');span.className = 'english-style';span.textContent = numberMatch[0];const textBefore = document.createTextNode(text.slice(lastIndex, numberMatch.index));parent.insertBefore(textBefore, node);parent.insertBefore(span, node);lastIndex = numberRegex.lastIndex;}// 添加剩余文本if (lastIndex < text.length) {const remainingText = document.createTextNode(text.slice(lastIndex));parent.insertBefore(remainingText, node);}parent.removeChild(node);}p.innerHTML = tempDiv.innerHTML;});// 将处理后的DOM转换回HTML字符串processedAnswer = serializeHTML(doc.body);processedList.value = processedAnswer}
}
const isStringNumber = (str) => {// 匹配整数、小数、负数const numberRegex = /^[-+]?(?:\d{1,3}(?:,\d{3})*(?:\.\d+)?|\d+(?:\.\d*)?|\.\d+)$/;return numberRegex.test(str);
};
// 转化为html
function parseHTML(htmlString) {const parser = new DOMParser();return parser.parseFromString(htmlString, 'text/html');
}
// 添加HTML序列化工具函数
function serializeHTML(node) {const temp = document.createElement('div');temp.appendChild(node.cloneNode(true));return temp.innerHTML;
}

px,pt,em换算表 | 菜鸟教程https://www.runoob.com/w3cnote/px-pt-em-convert-table.html像素与磅换算 -- EndMemohttps://endmemo.com/topography/pixelpointcn.html

http://www.dtcms.com/wzjs/283703.html

相关文章:

  • 做系统简单还是网站简单百度入口提交
  • 网站开发留学哈尔滨百度网站快速优化
  • 网站建设需要注意问题网络营销的概念及特征
  • 收废铁的做网站有优点吗免费的外链网站
  • 建网站引流做淘宝网站优化培训班
  • 旅游网站建设方案域名地址查询
  • 郑州汉狮哪家做网站好信息流投放平台
  • 上海网站建设网络公司餐饮品牌全案策划
  • 网站推广网站网站模板平台资源
  • 政务公开及网站建设意见中国疫情今天最新消息
  • wordpress .htaccess在哪里长尾词seo排名
  • 做网站做丝袜美女的能行吗深圳网站设计
  • 环艺做网站百度网盘资源
  • 网站空间指的是什么意思实时积分榜
  • 网站做302跳转的意义seo裤子的关键词首页排名有哪些
  • wordpress修复数据库宁波网站优化公司推荐
  • wordpress 文章截取毕节地seo
  • 网站 建设初步磁力链最好用的搜索引擎
  • 正品海外购网站有哪些营销策划是做什么
  • wordpress 笑话站上海网络关键词优化
  • 企业建设好一个网站后 如何进行网站推广2021年最为成功的营销案例
  • 公司外贸网站推广平台排名前十名
  • 接私活做预算的网站百度竞价推广开户费用
  • bootcdn WordPress优化大师app下载
  • 昆明云南微网站制作如何制作一个网站
  • 网站云空间和普通空间网站推广计划书范文500字
  • 一级a做爰片免费网站性恔免费友链互换
  • 福建商城网站制作公司我要学电脑哪里有短期培训班
  • 做网站page近期发生的新闻
  • 男女生做爰视频网站网络推广免费平台