首页 > web前端 > html教程 > Fluent HTML Tag Builder_html/css_WEB-ITnose

Fluent HTML Tag Builder_html/css_WEB-ITnose

WBOY
发布: 2016-06-24 11:27:05
原创
1044 人浏览过

来自: 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.

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板