<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(function(){
var root = "<div id='page'><div id='branding' class='clearfix'><div id='blog_name'><h1><a href='/admin' title='我的博客'>我的博客</a></h1></div><div id='blog_preview'><a href='/'><img alt='Icon_home' src='http://www.iteye.com/images/icon_home.gif?1324994303' />访问我的空间</a></div></div>";
//1.选择器
var tt =$(root).find('#branding').html();
alert(tt);
//xpath 选择器
var ttt =$(root).find("//div[id='branding']").html();
alert(ttt);
var url = 'http://m635674608.iteye.com/admin/blogs/2208989';
$.get(url,function(data){
root =data;
//2.和1一样的效果
var t =$(root).find('#header').html();
alert(t);
//xpath 选择器
var t2 =$(root).find("//div[id='header']").html();
alert(t2);
});
});
</script>
</head>
<body>
</body>
</html>
注意,字符串格式必须标准。<a></a>不规范可能解析不了