在下面的代码中,我想对其进行编辑,以便去掉第一行。
function update(url,cln){
$.ajax({
url: url,
dataType: "HTML",
error: function(msg){
alert(msg.statusText);
return msg;
},
success: function(html){
$("#main").html(html + '<a id="MAX"></a>');
}
});
}
例如,如果代码联系 url:http://stackoverflow.com/
网址返回:
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<div id="data">
<div id="test">
</div>
</div>
它会去掉第一行,这样当它把 html 写入 #main
时,它只会写:
<div id="data">
<div id="test">
</div>
</div>
最佳答案
您可以使用正则表达式来匹配从字符串开头到第一个换行符的所有内容:
html = html.replace(/^.*?\r?\n/, '');
演示:http://jsfiddle.net/Guffa/7pdqw/
正则表达式的解释:
^ - matches the beginning of the string
.*? - matches zero or more character, non-greedy
\r? - matches zero or one carriage return character
\n - matches a line feed character
关于javascript - 使用 jquery 从 ajax 查询导入数据时,从 html 中剥离/删除第一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20339259/