先说一下js获取url里面的域名地址 window.location.protocol+"//"+window.location.host; 这部分运行出来显示的是域名 这里是a连接里面的元素 <li> <a id="cont" href="" target="_blank"></a> </li> <li> <a id="hot" href="" target="_blank"></a> </li>
这一段显示的就是a连接写活的部分 <script> //先定义获取域名 var url= window.location.protocol+"//"+window.location.host; //其次往a连接里面填写地址 url是获取到的域名 +号是拼接上后面的地址 $("#cont").attr("href",url+'/index/index/cont.html'); $("#hot").attr("href",url+'/index/index/hot.html'); </script>
不懂的留言问我哦