如何在内容部分与模式匹配的页面中返回第一页的 url 部分(以函数 1 的样式,不区分大小写)但如果找不到页面则返回空字符串?
例如
url1(pages,"GREAT") 返回 "www.xyz.ac.uk"
url1(pages,"xyz") 返回 ""
到目前为止,这是我的代码:
var pg = [ "|www.cam.ac.uk|Cambridge University offers degree programmes and world class research." , "!www.xyz.ac.uk!An great University" , "%www%Yet another University" ];
var pt = "great";
function url1(pages, pattern) {
var result = "";
for (x in pages) {
current = pages[x].split(pattern);
result = current[1];
}
return result;
}
alert(url1(pg, pt));