簡體   English   中英

使用javascript檢查url參數

[英]Check url parameter using javascript

如果兩個網址是這樣的:

HTTP://本地主機:1113 /項目/ TestCourse.aspx ID =

HTTP://本地主機:1112 /項目/ TestCourse.aspx

如何使用javascript檢查'id'是否存在?

怎么樣:

/\?id\=|&id\=/i.test(location.href)

我會調整@KooiInc對location.href.match(/(\\?|&)id($|&|=)/)的回答。 它捕獲沒有值的參數(例如http:// localhost:1112 / Project / TestCourse.aspx?id ),並且還確保您只有id而不僅僅是以id開頭的param(例如idparam)。

使用location.href.match(/\\?id\\=/i) && location.href.match(/&id\\=/i)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM