您现在的位置是:首页 > 电脑技术查询 > web开发

一个jscript的有关问题,帮忙哈

编辑:chaxungu时间:2022-10-02 23:22:03分类:web开发

弱弱的问一个jscript的问题,帮忙哈
我写了一个取项目名称的代码:

var l = window.location.toString();

var u = l.split( "/ ");

var m = u[3]; //获取值赋值给m

theWebOffice.WebUrl= "http:// "+window.location.hostname+ "/ "+m+ "/OtherSource/UCMLOfficeServer.aspx "; //在这里取m这个值

我现在想把前面三句做成一个函数 然后在第四句里调用函数来取值 请教一下哈 没有

输入参数 只有一个输出这个函数怎么写呀 然后怎么调用呢?我刚开始接触这个,问

题比较。。不要笑话哈,先谢谢大家了


------解决方案--------------------
function loadM()
{
var l = window.location.toString();

var u = l.split( "/ ");

return u[3];
}

theWebOffice.WebUrl= "http:// "+window.location.hostname+ "/ "+loadM()+ "/OtherSource/UCMLOfficeServer.aspx "; //在这里取m这个值
------解决方案--------------------
function mm()
{
if(/http:\/\/[^/]+\/([^/]+)\//i.test(location.href)) return RegExp.$1;
return " ";
}

theWebOffice.WebUrl= "http:// "+ location.hostname + "/ "+ mm() + "/OtherSource/UCMLOfficeServer.aspx ";
------解决方案--------------------
function aa()
{
var l = window.location.toString();

var u = l.split( "/ ");

var m = u[3]; //获取值赋值给m
return m;
}
theWebOffice.WebUrl= "http:// "+window.location.hostname+ "/ "+aa()+ "/OtherSource/UCMLOfficeServer.aspx "; //在这里取m这个值