Javascript / jQuery Exec 结果为 Null
如果下一行结果为空,我如何跳过它?目前,它(有时)会“中断”并阻止脚本继续运行。
var title = (/(.*?)/m).exec(response)[1];
$.get(url, function(response){
var title = (/<title>(.*?)<\/title>/m).exec(response)[1];
if (title == null || title == undefined){
return false;
}
var words = title.split(' ');
$.each(words, function(index, value){
$link.highlight(value + " ");
$link.highlight(" " + value);
});
});
How do I skip over this next line if it turns out to be null? Currently, it (sometimes) "breaks" and prevents the script from continuing.
var title = (/(.*?)</title>/m).exec(response)[1];
$.get(url, function(response){
var title = (/<title>(.*?)<\/title>/m).exec(response)[1];
if (title == null || title == undefined){
return false;
}
var words = title.split(' ');
$.each(words, function(index, value){
$link.highlight(value + " ");
$link.highlight(" " + value);
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在获得索引 1 处的结果之前,您必须检查 title 是否不为 null
You must check that title is not null before you get the result at index 1