如果我对您的理解正确,请使用正则表达式在body标签之间获取内容。
$.get($(this).attr("href"), function(data) { var body=data.replace(/^.*?<body>(.*?)</body>.*?$/s,"$1"); $("body").html(body);});编辑
根据您在下面的评论,这是一个更新,以匹配任何body标签,无论其属性如何:
$.get($(this).attr("href"), function(data) { var body=data.replace(/^.*?<body[^>]*>(.*?)</body>.*?$/i,"$1"); $("body").html(body);});正则表达式为:
^ match starting at beginning of string.*? ignore zero or more characters (non-greedy)<body[^>]*> match literal '<body' followed by zero or more chars other than '>' followed by literal '>'( start capture .*?zero or more characters (non-greedy)) end capture</body> match literal '</body>'.*? ignore zero or more characters (non-greedy)$ to end of string
添加“ i”开关以匹配大写和小写字母。
并且请忽略我对’s’开关的评论,在Javascript中,默认情况下所有RegExp都已经是单行,要匹配多行模式,请添加’m’。(该死的Perl,在我写Javascript时干扰了我!:-)



