--- title: HTMLHyperlinkElementUtils.toString() slug: Web/API/HTMLAnchorElement/toString tags: - HTMLHyperlinkElementUtils.toString() - URL API translation_of: Web/API/HTMLHyperlinkElementUtils/toString original_slug: Web/API/HTMLHyperlinkElementUtils/toString ---
{{ApiRef("URL API")}}
HTMLHyperlinkElementUtils.toString() 方法返回一个包含整个URL的 {{domxref("USVString")}} 。它是{{domxref("HTMLHyperlinkElementUtils.href")}} 的一个只读版本。
string = object.toString();
/*
Let's imagine an
<a id="myAnchor" href="https://developer.mozilla.org/en-US/docs/HTMLHyperlinkElementUtils/toString">
 element is in the document
*/
var anchor = document.getElementById("myAnchor");
var result = anchor.toString();
// Returns: 'https://developer.mozilla.org/en-US/docs/HTMLHyperlinkElementUtils/toString'
| Specification | Status | Comment | 
|---|---|---|
| {{SpecName('HTML WHATWG', '#htmlhyperlinkelementutils', 'HTMLHyperlinkElementUtils.toString()')}} | {{Spec2('HTML WHATWG')}} | Initial definition. |