【发布时间】:2017-02-09 22:18:56
【问题描述】:
当我首先过滤数据时,它的 URL 就像这种类型
"http://localhost/computers?specs=Category:intel!!0!!".
但是当我第二次过滤时,它的 URL 会是这样的
"http://localhost/computers??specs=Category:intel!!0!!".
所以如果我第二次过滤删除'??',我只想这样做(问号)二选一。这是代码 `
<script type="text/javascript">
var currURL = window.location.href;
String.prototype.endsWith = function (currURL) {
var d = this.length - currURL.length;
return d >= 0 && this.lastIndexOf(currURL) === d;
};
</script>
`删除尾随 '?'来自网址(如果有)
【问题讨论】:
-
更好的解决方案是首先不要将第二个
?放在URL 中。网址是如何生成的? -
网址是通过我们的产品生成的。例如:localhost(这是我们的本地主机和)computers?specs=Category:intel!!0!! (这是我们的产品和类别)。那么我们可以删除“?”在“var currURL = window.location.href;”之后如果是的话,请给我建议。
-
正如 Rory 所说,最好不要把第二个
?放在首位。但是如果你以后必须删除它,你可以尝试var currURL = window.location.href; window.location.href = currURL.split("??").join("?"); -
谢谢亚历克斯。但是我尝试了这个,但它不起作用。还有什么办法吗?
-
@karan,为什么你允许添加第二次相同的过滤器?
标签: javascript c# jquery asp.net-mvc-4