【发布时间】:2010-08-09 08:12:16
【问题描述】:
如果两个 url 是这样的:
http://localhost:1113/Project/TestCourse.aspx?id=
http://localhost:1112/Project/TestCourse.aspx
如何使用javascript检查'id'是否存在?
【问题讨论】:
标签: javascript url
如果两个 url 是这样的:
http://localhost:1113/Project/TestCourse.aspx?id=
http://localhost:1112/Project/TestCourse.aspx
如何使用javascript检查'id'是否存在?
【问题讨论】:
标签: javascript url
怎么样:
/\?id\=|&id\=/i.test(location.href)
【讨论】:
我会调整@KooiInc 对location.href.match(/(\?|&)id($|&|=)/) 的回答。它捕获没有值的参数(例如http://localhost:1112/Project/TestCourse.aspx?id),并确保您只有 id 而不仅仅是以 id 开头的参数(例如 idparam)。
【讨论】:
使用location.href.match(/\?id\=/i) && location.href.match(/&id\=/i)
【讨论】: