更新URL参数与javascript/jquery与regEx
Update URL parameter with javascript/jquery with a regEx
我有一个web, URL是这样的:
http://www.example.com/index.php?mod=7&证交会= franquicias&月= 10,2013年=
里面有一个日期选择器;它应该改变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;
}
它似乎应该工作,现在奇怪的是,只有当url中的GET参数是&month=03,当有其他月份,url时,它才工作。Replace不能正确地替换url。重要的是要注意'paramVal'在函数'updateUrlParameter'它总是正确的;所以问题是在urlReplace从'function updateUrlParameter'。
谢谢你的帮助。
我不知道它是如何工作的,即使是month=03
。[0-9]{3}
正好匹配3位数字,而03
不匹配。正确的regexp是:
/'bmonth='d{2}'b/
相关文章:
- jQuery-Regex以防止任何特殊字符
- jQuery regex从文本链接-添加不需要的域到链接
- Jquery-Regex按键操作在Chrome和Firefox中有所不同
- jQuery regex标记换行
- 从字符串中jQuery Regex
- 自动替换为jquery regex
- jquery regex表达式警报框
- 使用jquery regex在文本字段中输入0到100
- If语句中的jQuery RegEx
- JQuery Regex - 获取字符串中的数字
- jquery / Regex,停止事件冒泡
- jquery REGEX for longstring with azAZ-09-specialchars and |
- 具有范围数值的输入框的KeyUp事件的Jquery Regex
- jQuery-RegEx工作异常
- jquery ui的客户端缓存自动完成:javascript/jquery regex匹配字符串"索引“;对象
- 使用jquery regex对空电子邮件地址进行验证
- jquery regex修补程序导致高cpu消耗
- jquery REGEX验证仅用于字母和数字u
- jQuery regex数据请求错误
- jQuery Regex匹配错误