jQuery获取本机ip地址
分类:实例代码
jQuery获取本机ip地址属于前端实例代码,有关更多实例代码大家可以查看。
在一些实际应用中可能会有这样的需求,那就是要获取本机的ip地址。
本章节分享一段代码示例,它能够实现此功能,不过要借助于外部的代码。
代码实例如下:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="renderer" content="webkit"> <link id="antzone" rel="Stylesheet" type="text/css"/> <title>前端教程网</title> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> <script language="javascript"> $(function($){ var url='http://chaxun.1616.net/s.php?type=ip&output=json&callback=?&_='+Math.random(); $.getJSON(url,function(data){ $("#show").text(data.Ip); }) }) </script> </head> <body> <div id="show"></div> </body> </html>
特别说明:上面的url地址随时可能失效,导致不能获取IP地址。
jQuery获取本机ip地址,这样的场景在实际项目中还是用的比较多的,关于jQuery获取本机ip地址就介绍到这了。