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

后端 未结 10 2144
眼角桃花
眼角桃花 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:06

    this function help you to get parameter from URL in JS

    function getQuery(q) {
        return (window.location.search.match(new RegExp('[?&]' + q + '=([^&]+)')) || [, null])[1];
    }
    

提交回复
热议问题