douxian4323
2015-02-25 13:13
浏览 81

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

below code working fine but I need to append option1 in href,

 $(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()?>");
                }
            });
        });
    });

now its return http://example.com/

I want like http://example.com/option1

I tried $(location).attr('href',"<?php echo $this->getBaseUrl()?>"option1); but failed to get, Thanks...

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanlisha2335 2015-02-25 13:16
    已采纳

    If option1 is a variable all you need is to concatenate with a + -

    $(location).attr('href',"<?php echo $this->getBaseUrl()?>" + option1)
    
    打赏 评论
  • doulian7252 2015-02-25 13:24

    You have your " at the wrong place, it should read:

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

    打赏 评论

相关推荐 更多相似问题