来自: https://github.com/rwhitmire/tag-builder
Fluent html tag building library.
npm install --save tag-builder
const assert = require('assert')const TagBuilder = require('tag-builder')const div = new TagBuilder('div')const html = div.text('hello world').toString()assert.equal(html, '<div>hello world</div>')const html = TagBuilder .create('input') .attr({ 'type': 'password', 'name': 'password' }) .addClass('form-control') .toString()assert.equal(html, '<input type="password" name="password" class="form-control">')const ul = TagBuilder.create('ul')const li1 = TagBuilder.create('li').text('1')const li2 = TagBuilder.create('li').text('2')ul.appendHtml(li1)ul.appendHtml(li2)const html = ul.toString()assert.equal(html, '<ul><li>1</li><li>2</li></ul>')Seetests for more examples.
All methods except toString() return a TagBuilder instance and are chainable.
立即学习“前端免费学习笔记(深入)”;
Returns a TagBuilder instance.
Sets innerHTML of the element. You may pass either a string or TagBuilder instance to this method.
Appends provided html to inner content. You may pass either a string or TagBuilder instance to this method.
Sets html encoded innerText of the element.
Appends html encoded text to inner content.
Merges attributes hash onto the tag.
Merges className onto the tag.
Returns html string.
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号