此示例正确验证 url。如何确定哪些未验证?我想在该部分触发单个警报else
或获取值以可能在其他地方使用。
function check_URL() {
var url = "http://" + localStorage['t'] + ".tumblr.com";
var url1 = "http://" + localStorage['t1'] + ".tumblr.com";
var url2 = "http://" + localStorage['t2'] + ".tumblr.com";
var url3 = "http://" + localStorage['t3'] + ".tumblr.com";
var urlArray = ['url', 'url1', 'url2','url3'];
$(urlArray).each(function (urlItem) {
$.getJSON("http://query.yahooapis.com/v1/public/yql?"+
"q=select%20*%20from%20html%20where%20url%3D%22"+
encodeURIComponent(urlItem)+
"%22&format=xml'&callback=?",
function(data){
if(data.results[0]){
console.log("yes");
}
else {
console.log("no");
alert("? is not a valid URL or is down.");
}
}
);
});
};
感谢新手的帮助!