如何在html字符串中获取标题标记? [英] How to get title tag in a string of html?
本文介绍了如何在html字符串中获取标题标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿我正在使用ajax将html页面加载到字符串中,现在我想找到页面的标题并使用它。
Hey i'm loading an html page using ajax into a string, now i want to find the title of the page and use it.
现在我做了管理使用正则表达式获取< title>
但是返回标记以及标题本身,我希望从字符串中提取该标记,或者是否有办法实现在正则表达式?
Now i did manage to get the <title>
using regex but that returns the tag along with the title itself and i wish to extract that from the string or could there be a way to do that in the regex?
这是我的代码:
var title = result.match(/<title[^>]*>([^<]+)<\/title>/);
现在我怎么得到这个/之后的实际标题呢?
Now how do i get the actuall title after this/ instead of this?
推荐答案
将你的响应html字符串加载到这样的jQuery对象中并检索文本
load your response html string into a jQuery object like so and retrieve the text
$(response).find("title").text();
这篇关于如何在html字符串中获取标题标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文