location.search是从当前URL的?号开始的字符串
如: http://www.51js.com/viewthread.php?tid=22720
它的search就是?tid=22720
要获取完整的地址
var url = window.location.search.substring(1,location.search.length);
如: http://www.51js.com/viewthread.php?tid=22720
它的search就是?tid=22720
要获取完整的地址
var url = window.location.search.substring(1,location.search.length);
<script type="text/javascript"></script>
本文介绍了一种从当前URL中提取查询参数的方法,通过使用JavaScript的location.search属性,可以方便地获取到URL中的?及其后的参数。这种方法对于需要解析URL参数的前端应用非常有用。
676

被折叠的 条评论
为什么被折叠?



