【发布时间】:2012-09-08 05:39:25
【问题描述】:
我有这样的 HTML 文本,它是使用 WinJS.xhr (Metro) 检索的。
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
</style>
</head>
<body>
<div id="getMe">
Something
</div>
</body>
</html>
我想将其转换为 JQuery 对象,以便在其上使用选择器。例如:
$("#getMe").text("Something different");
@马克: 我尝试使用它,但我无法获取文本。
var yourString = "<html><body><div id=\"getMe\">TEST</div></body></html>"// somehow set to the above string
$el = $(yourString).find("#getMe");
console.log($el.text());
【问题讨论】:
-
不知道你在这里问什么。 $("#getMe") 已经返回一个 jQuery 对象。这不是你想要做的吗?您可以将其分配给局部变量。 var $el = $("#getMe")
-
我的意思是我有 HTML 字符串变量。如何从该字符串中获取#getMe,甚至更改#getMe 的文本。
-
你的 HTML 字符串变量是什么?
-
>>> var myString = " ...