HTMLHyperlinkElementUtils.search 属性是一个搜索字符串,也叫做查询字符串, 它是一个 USVString ,包含 '?' 和随后的 URL 参数。
语法
string = object.search; object.search = string;
示例
// 让一个
// <a id="myAnchor" href="https://developer.mozilla.org/en-US/docs/HTMLHyperlinkElementUtils.search?q=123" />
// 元素在文档里
let anchor = document.getElementById("myAnchor");
let result = anchor.search;
// 返回:'?q=123'
规范
| Specification | Status | Comment |
|---|---|---|
| WHATWG HTML Living Standard HTMLHyperlinkElementUtils.search |
Living Standard | 初始定义 |
浏览器兼容性
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| 基本支持 | (Yes) [1] | (Yes) | 22 (22) [3][4] | (Yes) [2] | (Yes) [2] | (Yes) [2] |
| Feature | Android Webview | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|---|
| 基本支持 | (Yes) [1] | (Yes) [1] | (Yes) | 22.0 (22) [3][4] | (Yes) [2] | (Yes) [2] | (Yes) [2] |
[1] 自Chrome 52起,该属性移至URL
[2] 虽然没有被分在一个独立的抽象接口,但该方法可以在实现了它的那些接口上直接使用,如果支持该接口。
[3] 从Gecko 22 到 Gecko 44,该属性在 URLUtils mixin 上。它已经被移到 HTMLHyperlinkElementUtils mixin,或者直接在这个接口上。
[4] 在 Firefox 53之前, pathname 和 search HTMLHyperLinkElementUtils 属性返回的URL部分是错误的。例如,对一个值为 http://z.com/x?a=true&b=false 的URL,pathname 会返回"/x?a=true&b=false" ,search 会返回 "", 而不是各自返回 "/x" 和"?a=true&b=false" 。这已经被修正了。
相关链接
- 它属于
HTMLHyperlinkElementUtilsmixin 。