Closed apei830 closed 10 years ago
removeSearchParam : function(url, form) { $.each(form.serializeArray(), function() { var name = this.name; url = url.replace(new RegExp(name + "=.?&","g"), ''); url = url.replace(new RegExp("[&\?]" + name + "=.$","g"), ''); }); return url; },
应该使用非饥渴模式 url = url.replace(new RegExp(name + "=.&","g"), ''); 饥渴 url = url.replace(new RegExp(name + "=.?&","g"), ''); 非饥渴,尽量少匹配
原来的正则会有如下bug:
http://localhost:9090/eas/admin/showcase/sample/sample/list2.html?aaa=12&bbb=&ccc=&page.orderBy=email&page.order=asc
当循环form里的参数aaa时,会一直匹配到page.order为止,中间的所有参数都会被remove掉,变成: http://localhost:9090/eas/admin/showcase/sample/sample/list2.html?page.order=asc
fixed
removeSearchParam : function(url, form) { $.each(form.serializeArray(), function() { var name = this.name; url = url.replace(new RegExp(name + "=.?&","g"), ''); url = url.replace(new RegExp("[&\?]" + name + "=.$","g"), ''); }); return url; },
应该使用非饥渴模式 url = url.replace(new RegExp(name + "=.&","g"), ''); 饥渴 url = url.replace(new RegExp(name + "=.?&","g"), ''); 非饥渴,尽量少匹配
原来的正则会有如下bug:
http://localhost:9090/eas/admin/showcase/sample/sample/list2.html?aaa=12&bbb=&ccc=&page.orderBy=email&page.order=asc
当循环form里的参数aaa时,会一直匹配到page.order为止,中间的所有参数都会被remove掉,变成: http://localhost:9090/eas/admin/showcase/sample/sample/list2.html?page.order=asc