Javascript / jQuery Exec出现Null

时间:2010-05-27 08:11:41

标签: javascript jquery null exec

如果结果为空,我如何跳过下一行?目前,它(有时)“中断”并阻止脚本继续。

var title =(/(。*?)< / title> / m).exec(回复)[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);
    });
 });        

1 个答案:

答案 0 :(得分:3)

$.get(url, function(response){
    var title = (/<title>(.*?)<\/title>/m).exec(response);
    if (!title || !title[1]){
        return false;
    }
    title=title[1];
    var words = title.split(' ');
    $.each(words, function(index, value){
        $link.highlight(value + " ");
        $link.highlight(" " + value);
    });
 });

你必须检查标题是否为空之前你在索引1得到结果

相关问题