我想把字符串s转化为jquery对象,然后对其进行选择,但是如下代码并没有得到我想要的结果,请各位帮我看看,不胜感激!
var s = "<p>one</p> <div><p>two</p></div> <p>three</p>"
var tt=$(s).find("div > p");
alert(tt.html());
var s = "<p>one</p> <div><p>two</p></div> <p>three</p>"
var tt=$(s).find("div > p");
alert(tt.html());
var tt=$("<html>"+s+"</html>").find("div > p");
alert(tt.html());
<html><head>
<script type="text/javascript" charset="gb2312" src='jquery-1.3.2.min.js'></script>
<meta http-equiv="content-type" content="text/html; charset=gb2312"/>
<script type="text/javascript">
$(document).ready(function()
{
var s = " <p>one </p> <div> <p>two </p> </div> <p>three </p>"
var tt=$("<html>"+s+"</html>").find("div > p");
alert(tt.html());
});
</script>
<title></title></head><body>
</body></html>
{
var s = " <p>one </p> <div> <p>two </p> </div> <p>three </p>"
var tt=$(" <div>"+s+" </div>").find("div > p");
alert(tt.html());
}); 原来<html>他不认...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head> <body>
<script type="text/javascript" src="jquery-1.2.6.js"></script>
<script type="text/javascript">
<!--
var s = "<p>one </p> <div><p>two </p> </div><p>three </p>"
var tt=$("<div>" + s + "</div>").find("div > p");
alert(tt.html());
//-->
</script>
</body>
</html>
var s = "<html><body><p>one </p> <div> <p>two </p> <p>three</p></div> <p>three </p></body></html>"
var tt=$(" <div>"+s+" </div>").find("p");
alert(tt.html());
它返回的只是第一个“one”,而不返回其它的,请问这又是什么原因?而且为什么非要加个"<div>"呢?