使用jQuery在url中附加(添加)文本


append(add) a text in url using jQuery

下面的代码运行良好,但我需要在href,中添加option1

 $(document).ready(function () {
        $("#head_drop .dd-option").click(function () {
            var option = $('.dd-option-value',this).attr('value');
            var option1 = $('.dd-option-text',this).text();
           // alert(option1);
            $.ajax({
                type: 'get',
                url: '<?php echo $this->getBaseUrl();?>categories/index/city/',
                data: {option: option},
                success: function(data) {
                    $(location).attr('href',"<?php echo $this->getBaseUrl()?>");
                }
            });
        });
    });

现在它回来了http://example.com/

我想要http://example.com/option1

我试过$(location).attr('href',"<?php echo $this->getBaseUrl()?>"option1);,但没有成功,谢谢。。。

如果option1是一个变量,您只需要连接一个+-

$(location).attr('href',"<?php echo $this->getBaseUrl()?>" + option1)

您的"放错了位置,它应该是:

$(location).attr('href',"<?php echo $this->getBaseUrl()?>option1");