How to change the querystring when I submit my GET form using JQuery?

后端 未结 3 1293
抹茶落季
抹茶落季 2020-12-19 12:25

Suppose that I have a simple form in my page like this :

3条回答
  •  臣服心动
    2020-12-19 12:55

    You're almost there. Intercept the submit event (as you are doing), extract the min and max values, build your url and set window.location.href

    $(document).ready(function() {
        $("#form_search").submit(function(event) {
            event.preventDefault();
            $this = $(this);
            // var url = rewrite_interval_qstring();
            var min_price = $('#min_price').val();
            var max_price = $('#max_price').val();
            var url = $this.attr('action') + '?price=' + min_price + ',' + max_price;
            window.location.href = url;
        });
    });
    

提交回复
热议问题