您的位置:首页 > 其它

项目杂记一

2015-06-17 20:10 351 查看
把webappbuilder自动生成的env.js拷贝到VS项目文件夹中,需要注意代码替换。

主要是对正则表达式和js的两个方法的理解。

pop()方法:JS中pop()方法用于删除并返回数组的最后一个元素。

test()方法:用于检测字符串是否匹配某个模式。

所以要把以下代码

function getPath() {
  var fullPath, path;

  fullPath = window.location.pathname;
  if (fullPath === '/' || fullPath.substr(fullPath.length - 1) === '/') {
    path = fullPath;
  } else if (/\.html$/.test(fullPath.split('/').pop())) {
    var sections = fullPath.split('/');
    sections.pop();
    path = sections.join('/') + '/';
  } else {
    return false;
  }
  return path;
}


替换成

function getPath() {

var fullPath, path;



fullPath = window.location.pathname;

alert("你好");

if (fullPath === '/' || fullPath.substr(fullPath.length - 1) === '/') {

path = fullPath;

}

// pop() 方法用于删除并返回数组的最后一个元素。

else if (/\.aspx$/.test(fullPath.split('/').pop())) {

var sections = fullPath.split('/');

sections.pop();

path = sections.join('/') + '/';

} else {

return false;

}



return path;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: