用js写一个和PHP的explode一模一样的函数
写一个和PHP的explode函数一模一样的JS函数作用效果一样,输入的参数也一样,全部一样,返回数组谢...
写一个和PHP的explode函数一模一样的JS函数
作用效果一样,输入的参数也一样,全部一样,
返回数组
谢 展开
作用效果一样,输入的参数也一样,全部一样,
返回数组
谢 展开
展开全部
split,基础要打牢固
var arrstr = document.cookie.split(";");
for(var i=0; i<arrstr.length;i++)
{
var temp = arrstr[i]
}
var arrstr = document.cookie.split(";");
for(var i=0; i<arrstr.length;i++)
{
var temp = arrstr[i]
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
function explode(inputstring, separators, includeEmpties) {
inputstring = new String(inputstring);
separators = new String(separators);
if(separators == "undefined") {
separators = " :;";
}
fixedExplode = new Array(1);
currentElement = "";
count = 0;
for(x=0; x < inputstring.length; x++) {
str = inputstring.charAt(x);
if(separators.indexOf(str) != -1) {
if ( ( (includeEmpties <= 0) || (includeEmpties == false)) && (currentElement == "")) {
}
else {
fixedExplode[count] = currentElement;
count++;
currentElement = "";
}
}
else {
currentElement += str;
}
}
if (( ! (includeEmpties <= 0) && (includeEmpties != false)) || (currentElement != "")) {
fixedExplode[count] = currentElement;
}
return fixedExplode;
}
inputstring = new String(inputstring);
separators = new String(separators);
if(separators == "undefined") {
separators = " :;";
}
fixedExplode = new Array(1);
currentElement = "";
count = 0;
for(x=0; x < inputstring.length; x++) {
str = inputstring.charAt(x);
if(separators.indexOf(str) != -1) {
if ( ( (includeEmpties <= 0) || (includeEmpties == false)) && (currentElement == "")) {
}
else {
fixedExplode[count] = currentElement;
count++;
currentElement = "";
}
}
else {
currentElement += str;
}
}
if (( ! (includeEmpties <= 0) && (includeEmpties != false)) || (currentElement != "")) {
fixedExplode[count] = currentElement;
}
return fixedExplode;
}
来自:求助得到的回答
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询