Elegant clean way to include HTML in JavaScript files?

后端 未结 7 2163
误落风尘
误落风尘 2020-12-23 10:05

I\'m building a small app with a few modal dialog windows. The windows require a tiny bit of HTML. I\'ve hard coded the window HTML in the javascript library but am not th

7条回答
  •  鱼传尺愫
    2020-12-23 10:36

    Cook.js

    div([
      button({click:[firstEvent, secondEvent]},
             'You can bind (attach) events on the fly.'),
      p('Here are some popular search engines'),
      ul([
        li([
          a('Google', {href:'http://www.google.com'})
        ]),
        li([
          a('Bing', {href:'http://www.bing.com'})
        ]),
        li([
          a('Yahoo', {href:'http://www.yahoo.com'})
        ])
      ])
    ]);
    

    how it works

    Objects = Attribute & Events
        -> {href:'facebook.com', src:'static/cat.gif', ng-bind:'blah'}
    String  = Text or Html
        -> 'hello world'
    Array   = Elements
        -> [a('hello world', {href:'facebook.com'}), img({src:'static/cat.gif'})] 
    

    more on cook.js!

提交回复
热议问题