获取url中的参数\+发送ajax请求根路径|+获取复选框的值

//获取url中的参数
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
if (r != null) return unescape(r[2]); return null; //返回参数值
}

eg:

var workerId=getUrlParam("workerId");
var leaderId=getUrlParam("leaderId");
var phone=getUrlParam("phone");

function getRootPath() {
//获取当前网址,如: /meun.jsp
var curWwwPath = window.document.location.href;
//获取主机地址之后的目录,如: proj/meun.jsp
var pathName = window.document.location.pathname;
var pos = curWwwPath.indexOf(pathName);
//获取主机地址,如: http://localhost:8083
var localhostPath = curWwwPath.substring(0, pos);
//获取带"/"的项目名,如:/proj
var projectName = pathName.substring(0, pathName.substr(1).indexOf(
'/') + 1);
return (localhostPath + projectName);
}

//js遍历选中的复选框的值
var obj=document.getElementsByName("inlineCheckbox1"); //选择所有name="'test'"的对象,返回数组
var type=[];
var typeDisplay=[];
for(var i=0;i<obj.length; i++){
if(obj[i].checked){

if(7==obj[i].value){
  work_type=7;
  work_type_display="速度";
  }else if(8==obj[i].value){
  work_type=8;
  work_type_display="说得对";

}

  type.push(work_type);
  typeDisplay.push(work_type_display);
  var workType=type.toString();
  var workTypeDisplay=typeDisplay.toString();
  console.log(workType);
  console.log(workTypeDisplay);
  }
}

上一篇:Codevs 1629 01迷宫


下一篇:JavaScript获取地址栏中的参数