JavaScript 有类似 simple_html_dom.php 的东西吗?
我正在使用 Appcelerator Titanium 构建 iPhone 应用程序,并且需要将 HTML 字符串(其中可能包含无效的 HTML,如缺少标签,这不是我的错)转换为 DOM 对象。在此 DOM 元素中,我需要找到特定的
,并将此
的内容放入 WebView 中。不管怎样,我正在寻找类似于 Simple HTML DOM 脚本的东西,该脚本用于 PHP,通过 DOM 进行搜索对于这个
。我希望脚本扫描(无效)HTML 字符串,并获取
的innerHTML。我怎样才能最好地在 JavaScript 中做到这一点?
I'm building an iPhone app using Appcelerator Titanium, and I need to convert a HTML string (which may contain invalid HTML like missing tags, not my fault) to a DOM object. In this DOM element I need to find a specific <div>
, and put the contents of this <div>
in a WebView.
Anyway, I am looking for something like the Simple HTML DOM script, which is for PHP, to search through the DOM for this <div>
. I'd like the script to scan the (invalid) HTML string, and get the innerHTML of the <div>
.
How can I best do this in JavaScript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面的代码是基本的字符串到 DOM 转换器。请参阅链接的答案以获取详细说明。
此代码片段不会净化 HTML。将执行脚本,将加载外部源。代码的解释和 HTML 清理程序可以在 这个答案
用法(示例),小提琴:http://jsfiddle.net/JFSKe/:
The code below is the basic string-to-DOM convertor. See the linked answer for a detailed explanation.
This code snippet does not sanitise the HTML. Scripts will be executed, external sources will be loaded. The explanation of the code, and HTML sanitiser can be found at this answer
Usage (examples), Fiddle: http://jsfiddle.net/JFSKe/: