Skip to content

引入

ts
import { insertStyle, insertHtml } from 't-comm';

// 不支持 tree-shaking 的项目
import { insertStyle, insertHtml} from 't-comm/lib/dom/index';

// 只支持 ESM 的项目
import { insertStyle, insertHtml} from 't-comm/es/dom/index';

insertStyle(options)

描述:向页面 head 中插入 style 标签 如果已存在相同 id 的 style 标签,会先移除再插入新的

参数

参数名描述
options配置选项
options.idstyle 标签的 id
options.contentCSS 样式内容

示例

ts
insertStyle({
  id: 'custom-style',
  content: '.my-class { color: red; }'
});

insertHtml(options)

描述:向页面 body 中插入隐藏的 HTML 元素 如果已存在相同 id 的元素,会先移除再插入新的

参数

参数名描述
options配置选项
options.iddiv 元素的 id
options.contentHTML 内容

示例

ts
insertHtml({
  id: 'hidden-content',
  content: '<div>隐藏的内容</div>'
});