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

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

    var field = 'q';
    var url = window.location.href;
    if(url.indexOf('?' + field + '=') != -1)
        return true;
    else if(url.indexOf('&' + field + '=') != -1)
        return true;
    return false
    

提交回复
热议问题