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]提供し、html文字列を提供します。HTMLAnchorElementHTMLAnchorElement.outerHTML

于 2012-07-06T03:41:55.007 に答える
0

Check out this link.

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 に答える