Skip to content

Instantly share code, notes, and snippets.

@tiye
Created May 20, 2012 07:29
Show Gist options
  • Select an option

  • Save tiye/2757183 to your computer and use it in GitHub Desktop.

Select an option

Save tiye/2757183 to your computer and use it in GitHub Desktop.
关于网页的生成

关于网页编写的一些点子

页面定义变量以便在网页中使用:

title = 'Title of Demo'
name = 'Another Title'
f1 = (x)  -> console.log 'given x:', x

makeHTML 函数生成文档树, 返回 html 对象用于操作:

html = makeHTML
  head
    title title
    link
      rel  'sylesheet'
      href 'local'
  body
    div
      id 'handler'

用将内容绑定到文档全局:

window.HTML = html

html 是一个对象, 向下访问, 直到 title, 有方法比如 change_to:

html/head/title/change_to name

title 的内容通过其属性访问:

html/head/title/innerText

通过 id 访问单个标签:

handler = docu.getById 'handler'

向指定元素添加更多 HTML 自动生成的内容,
但是比如事件, 也是可以用 HTML 自动完成绑定的:

handler.appendHTML
  div
    innerHTML 'appended things'
    event f1

然后更改事件为访问同一对象同一层其他属性:

handler.div.event = console.log @innerHTML

上面的想法有不少的常识性错误. 只是想说明下关于网页的想法而已.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment