js获取ip本机ip地址 发表于 2023-11-12 | 更新于: 2024-03-10 | 分类于 前端 , JS | 阅读次数: | 浏览量 请求一个公共接口即可,详情请看:12345678910111213141516171819function getip() { var ip = ""; var xhr = new XMLHttpRequest(); // false参数代表同步请求 xhr.open("GET", "https://api.ipify.org", false); xhr.onreadystatechange = function() { if(xhr.readyState === 4) { if(xhr.status === 200) { ip = xhr.responseText; //买家ip console.log(ip); }else{ console.error(xhr.statusText); } } }; xhr.send(null); return ip;}好记性不如烂笔头。-------------本文结束感谢您的阅读-------------