0

可以帮助我解决 jquery 对象问题。

问题如下,我有这个代码:

url = '<a href="http://url.com">Name</a>';
otherValue = "Other Value";

x = jQuery(url).text(otherValue);
console.log(x);         
console.log(typeof(x));

这个回报:

[<a href=​"http:​/​/url.com">​Other Value​&lt;/a>​]
object 

我如何制作这个对象并最终得到一个字符串?

谢谢

4

2 回答 2

2

尝试console.log(x[0].outerHTML);

解释:x[0]给你HTMLAnchorElement对象,HTMLAnchorElement.outerHTML给你 html 字符串。

于 2012-07-06T03:41:55.007 回答
0

看看这个链接。

url = '<a href="http://url.com">Name</a>';
otherValue = "Other Value";

x = jQuery(url).text(otherValue);
alert(x[0].outerHTML);

http://jsfiddle.net/SRjfq/

于 2012-07-06T03:52:28.197 回答