如何检查URL格式

时间:2015-05-13 11:58:30

标签: javascript jquery asp.net-mvc

我想检查网址格式是否为@Url.Content("~/Dashboard/Index?studentId=")。如果是,我们必须设置@Url.Content("~/Dashboard/Index"),如果不是window.location.href。怎么做?

var currentUrl = (@Url.Content("~/Dashboard/Index?studentId=")) ? (@Url.Content("~/Dashboard/Index")) :  window.location.href;
if (currentUrl.indexOf('#') > -1) {
    currentUrl = currentUrl.replace('#', '');
}
else {
    currentUrl += '#';
}
window.location.href = currentUrl;

0 个答案:

没有答案