将html转换为javascript [英] convert html to javascript

查看:100
本文介绍了将html转换为javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如:

有人知道是否有可以将html转换为javascript的工具。 pre> < DIV>
< / div>

会转换为

  aDiv = document.createElement('div'); 
document.appendChild(aDiv);

etc



我在做用于UI组件的几个html模板,并使用MooShell进行原型设计。能够自动生成构建组件的html的javascript会很棒。



谢谢

解决方案

我建议看看John Resig的纯JavaScript HTML分析器。它由用于HTML的SAX样式解析器组成,并包含一个XML序列化器,一个DOM构建器和一个DOM创建器。每个都需要一个HTML字符串作为输入。特别是,HTMLtoDOM方法可以很容易地重新用于返回构建DOM所需的任何输入字符串所需的JavaScript字符串HTML。


Does anybody know if there is a tool around that can convert html to javascript.

For example:

<div>
</div>

would convert to

aDiv = document.createElement('div');
document.appendChild(aDiv);

etc

I'm am doing a few html templates for UI components and am using MooShell for prototyping. It would be great to be able to auto-generate the javascript that will build the component's html.

Thanks

解决方案

I'd suggest taking a look at John Resig's pure javascript HTML parser. It consists of a SAX style parser for HTML and includes an XML serializer, a DOM builder and a DOM creator. Each takes a string of HTML as input.

In particular, the HTMLtoDOM method could easily be repurposed to return the string of javascript required to build the DOM for any input string of HTML.

这篇关于将html转换为javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆