How to use jquery to manipulate the querystring

后端 未结 6 2029
别跟我提以往
别跟我提以往 2021-02-08 22:36

I have a select dropdown with id\'s mapped to values. On the onChange event I want to redirect to the same url but with \'id=value\' appended to the querystring.

How do

6条回答
  •  青春惊慌失措
    2021-02-08 23:33

    I suspect the alleged solution is not working with specific variable names. Especially the line:

    RegExp( ';?' + key + '=?[^&;]*', 'g' )
    

    If key is a character sequence present elsewhere within the querystring, that occurrence will be mistakenly replaced also (try one letter, e.g. 'a'). This is because the regex leaves the string boundaries open (leading ';' and trailing '=' are both optional). Maybe the epxression better be something like:

    RegExp( '[;&]' + key + '=?[^&;]*', 'g' )
    

    Though I haven't tested it yet.

提交回复
热议问题