How to use jquery to manipulate the querystring

后端 未结 6 2026
别跟我提以往
别跟我提以往 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:19

    This works like a charm:

    jQuery.redirect = function( url ) {
       window.location.replace( url );  
    };
    $( "#selector" ).change( function() {
        var href = window.location.href.substring( 0, window.location.href.indexOf( '?' ) );
        $.redirect( href + '?id=' + $( this ).val() );
    } );
    

提交回复
热议问题