使用带有正则表达式的javascript/jquery更新URL参数

使用带有正则表达式的javascript/jquery更新URL参数,javascript,jquery,url,Javascript,Jquery,Url,我有一个网址如下: 里面有一个日期选择器;应该更改get参数的月份和年份;然后重新加载页面 在HTML中,我在负责减少日期的按钮中执行以下操作: <button type="button" class="btnIcon previous lbutton" onclick="changeMonth('previous',{$smarty.get.month},{$smarty.get.year})"> 必须使用的javascript函数是: function chang

我有一个网址如下:

里面有一个日期选择器;应该更改get参数的月份和年份;然后重新加载页面

在HTML中,我在负责减少日期的按钮中执行以下操作:

<button type="button" class="btnIcon previous lbutton" onclick="changeMonth('previous',{$smarty.get.month},{$smarty.get.year})">

必须使用的javascript函数是:

    function changeMonth(changeType, month, year){
    changeMonth;

    switch (changeType){
    case "previous":
        changeMonth = month-1;
        if (changeMonth <= 0) changeMonth = 12;
        if (changeMonth < 10) changeMonth = "0"+changeMonth;
        window.location = updateURLParameter($(location).attr('href'), month, changeMonth);
        break;
    case "next":
        break;
    }       
}

function updateURLParameter(url, param, paramVal){

    var regEx = /month=[0-9]{3}/;
    console.log("paramVal: "+paramVal);
            // paramVal here is ever correct.
    var newUrl = url.replace(regEx, 'month='+paramVal);

    console.log(newUrl);
    return newUrl;
}
功能变更月(变更类型、月、年){
改变月份;
开关(转换型){
“以前”一案:
changeMonth=第1个月;

如果(changeMonth我看不出它是如何工作的,即使是
month=03
[0-9]{3}
正好匹配3位数字,而
03
与之不匹配。正确的regexp是:

/\bmonth=\d{2}\b/

尝试
/month=[0-9]{1,3}/
如果我写
/month=[0-9]{1,3}/
页面没有加载…但是你给了我尝试
/month=[0-9]*/
的想法,它正在工作;谢谢你。