【问题标题】:error in creating query string using anchor tag使用锚标记创建查询字符串时出错
【发布时间】:2016-09-27 13:05:59
【问题描述】:

当我使用锚标记传递查询字符串时,我得到了我的 url,但问题是 processorId=51 重复两次 我的弦就这样来了 MonthlySettlementAlgorithm/MonthlySettlementResultviewByDate?processorId=51&bankId=51&bankId=2866

但我是预期的

MonthlySettlementAlgorithm/MonthlySettlementResultviewByDate?processorId=51&bankId=2866

请给我解决办法

+ "<li><a target='_blank'  href='/MonthlySettlementAlgorithm/MonthlySettlementResultviewByDate?processorId=' >View By Date</a></li>"

 + "<li><a target='_blank' href='/MonthlySettlementAlgorithm/MonthlySettlementResultViewByBank?processorId=' >View By Bank</a></li>"

    Jquery Code 

         $('.dropdown-menu.features li a').each(function () {
            if ($(this).attr('href'))
            {
                $(this).attr('href', $(this).attr('href') + selectedProcessorIds +'&bankId='+ selectedBankIds);
            }
        });

【问题讨论】:

  • 在 js 中构建 a 标签时初始设置 href='/MonthlySettlementAlgorithm/MonthlySettlementResultviewByDate'
  • 我已经尝试过这条线,但我没有得到准确的结果

标签: javascript jquery angularjs asp.net-mvc


【解决方案1】:

我终于找到了解决办法

 $('.dropdown-menu.features li a').each(function () {

    var href = $(this).attr('href');
    if (href) {
        var requiredArray = href.split('?');

        if (requiredArray.length > 1) {
            var tempProcString = "processorId=" + selectedProcessorIds;
            var tempBankString = "&bankId=" + selectedBankIds;
            var tempDate = "&snapshotDate=" + $('#txtDate_FirstDateValue').val();
            requiredArray[1] = tempProcString + tempBankString + tempDate;
            console.log(requiredArray[1]);
        }

        //finally updating href
        $(this).attr('href', requiredArray.join('?'));
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-01
    • 1970-01-01
    • 2018-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多