可以jQuery的解析HTML保存在一个变量? [英] Can jQuery Parse HTML Stored in a Variable?

查看:144
本文介绍了可以jQuery的解析HTML保存在一个变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP和AJAX的命令采取外部网页的整个HTML内容(通过PHP 的file_get_contents()命令),并通过该HTML到一个javascript变量。有一次,我都存储在一个变量页面的HTML内容,我可以使用jQuery与该变量的内容进行交互,以同样的方式,jQuery的正常与DOM交互?在这个例子中,我试图寻找某些HTML元素(&LT的存在; DIV> <脚本> 标签)与特定ID属性。任何人都可以建议我怎么能做到这一点?

I'm using PHP and an ajax command to take the entire HTML contents of an external web page (via the PHP file_get_contents() command) and passing that HTML into a javascript variable. Once I have the page's HTML contents stored in a variable, can I use jQuery to interact with the contents of that variable, in the same way that jQuery normally interacts with the DOM? In this example, I am trying to search for the existence of certain HTML elements (<div> and <script> tags) with specific ID attributes. Can anyone suggest how I can accomplish this?

推荐答案

如果我理解正确的话,你应该能够变量只是传递给jQuery的功能和相应的工作。

If I understand you correctly, you should be able to just pass the variable to the jQuery function and work accordingly.

一个简单的例子与 .filter()

$(myHtml).filter('#someid').doStuff();

这篇关于可以jQuery的解析HTML保存在一个变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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