手册目录
JS教程
JS版本
JS HTML DOM
JS Web API
JS AJAX
JS JSON
JS vs jQuery
JS参考手册
API 指的是应用程序编程接口(Application Programming Interface)。
Web API 是 Web 的应用程序编程接口。
浏览器 API 可以扩展 Web 浏览器的功能。
服务器 API 可以扩展 Web 服务器的功能。
所有浏览器都有一组内置的 Web API 来支持复杂的操作,并帮助访问数据。
例如,Geolocation API 可以返回浏览器所在位置的坐标。
获取用户所在位置的经纬度:
const myElement = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
myElement.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
myElement.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
运行实例 »点击 "运行实例" 按钮查看在线实例
第三方 API 未内置于您的浏览器中。
要使用这些 API,您必须从 Web 下载代码。
相关视频
科技资讯
24小时阅读榜
1
2
3
4
5
6
7
8
9
10
精品课程
共5课时 | 17.4万人学习
共49课时 | 78.2万人学习
共29课时 | 62.5万人学习
共25课时 | 39.7万人学习
共43课时 | 73.8万人学习