日期:2014-05-16  浏览次数:20553 次

关于js replace 过滤网址中的url字体的小问题,大神请进
一个网址的字符串siteUrl的值是【&brand=%B5%D9%DC%BD%C4%E1&page=12】,要做的就是在js中【&brand=%B5%D9%DC%BD%C4%E1】这些字符串替换清除,brand的字符串可能会经常不一样,但是都是文字转成的url码。

我知道【&page=12】的清除掉的方法是siteUrl.replace(/(\&page=(\d+))/ig,'');。

那请问下下清除掉siteUrl中【&brand=%B5%D9%DC%BD%C4%E1】这个字符串应该怎么写呢??~~~

------解决方案--------------------
siteUrl="&brand=%B5%D9%DC%BD%C4%E1&page=12"
siteUrl=siteUrl.replace(/&brand=[^&]+/ig,'');。
alert(siteUrl)

------解决方案--------------------

<script type="text/javascript">
siteUrl="&brand=%B5%D9%DC%BD%C4%E1&page=12"
siteUrl=siteUrl.replace(/&brand=(%\w+)*/ig,'');
alert(siteUrl)
</script>