它应该做什么 - 实施例
url1(pages,"ALT") returns "www.xyz.ac.uk"
url1(pages,"xyz") returns ""
错误 - ReferenceError: ALT is not defined
这只是为了一些课程,我坚持这些错误。任何帮助将不胜感激
function index(string,pattern,caseSensitive) {
if(caseSensitive == false) {
var v = string.toUpperCase();
} else {
var v = string;
}
return indexNumber = v.indexOf(pattern);
}
var pages = [ "|www.lboro.ac.uk|Loughborough University offers degree programmes and world class research.", "!www.xyz.ac.uk!An alternative University" , "%www%Yet another University"];
alert(url1(pages, ALT));
function url1(pages,pattern) {
var siteContent = [];
for(i=0;i<pages.length;i++) {
var seperator = pages[i].charAt(0);
if(pages[i].indexOf(seperator)>0){
siteContent = pages[i].split(pages[i].indexOf(seperator));
}
if( index(siteContent[2],pattern,false)>=0){
return siteContent[1];
}else{
return "";
}
}
}
答案 0 :(得分:2)
所以你这样称呼它:
alert(url1(pages, ALT));
此处alt未定义,因为ALT不是已定义的变量。
用字符串调用它?
url1(pages,"ALT");