How to check if a query string value is present via JavaScript?

后端 未结 10 1902
眼角桃花
眼角桃花 2021-01-30 00:25

How can I check if the query string contains a q= in it using JavaScript or jQuery?

10条回答
  •  遥遥无期
    2021-01-30 01:17

    I've used this library before which does a pretty good job of what you're after. Specifically:-

    qs.contains(name)
        Returns true if the querystring has a parameter name, else false.
    
        if (qs2.contains("name1")){ alert(qs2.get("name1"));}
    

提交回复
热议问题