代码之家  ›  专栏  ›  技术社区  ›  Matrym

Javascript/jQuery Exec显示为空

  •  0
  • Matrym  · 技术社区  · 16 年前

    变量标题=(/(*?)</标题>/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 回复  |  直到 16 年前
        1
  •  3
  •   mck89    16 年前
    $.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得到结果