| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
tangmai
8年前发布

Fluent HTML Tag Builder

来自: https://github.com/rwhitmire/tag-builder

tag-builder

Fluent html tag building library.

Install

npm install --save tag-builder

Examples

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.

API

All methods except toString() return a TagBuilder instance and are chainable.

create(tagName: string)

Returns a TagBuilder instance.

html(html: any)

Sets innerHTML of the element. You may pass either a string or TagBuilder instance to this method.

appendHtml(html: any)

Appends provided html to inner content. You may pass either a string or TagBuilder instance to this method.

text(text: string)

Sets html encoded innerText of the element.

appendText(text: string)

Appends html encoded text to inner content.

attr(attributes: object)

Merges attributes hash onto the tag.

addClass(className: string)

Merges className onto the tag.

toString()

Returns html string.

 本文由用户 tangmai 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1455078640230.html
HTML