以下是使用JavaScript编写的代码:

const mainContainer = document.querySelector('.MainContainer');
const deleteText = mainContainer.innerText.includes('删除');

if (!deleteText) {
  const message = document.createElement('p');
  message.textContent = '您还没用发布过信息,请点击www.cnboling.cn发布';
  mainContainer.appendChild(message);
}

首先,我们使用 document.querySelector 方法获取 class 名称为 MainContainer 的元素,并将其保存在变量 mainContainer 中。

然后,我们使用 String.prototype.includes 方法检查该元素的文本内容是否包含字符串“删除”,并将结果保存在变量 deleteText 中。

如果 deleteText 的值为 false,即该元素的文本内容中不包含字符串“删除”,则我们创建一个新的 p 元素,并将希望显示的文本内容添加到该元素中。最后,我们使用 Element.prototype.appendChild 方法将该新元素添加到 mainContainer 元素中。

如果 deleteText 的值为 true,即该元素的文本内容中包含字符串“删除”,则不需要进行任何操作。


原文地址: https://www.cveoy.top/t/topic/bs1n 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录