4
此代碼獲取HTML數據,並應取代所有的JavaScript內容的Javascript正則表達式修飾符
$.ajax({
url: url,
success: function(data){
data = data.replace(/<script.*?<\/sc/mg,'');
alert(data);
},
dataType: 'html'
});
但有留的JavaScript代碼data
.....</div><!-- end header -->
<div id="snapshot">
<a href="?cat=<div style=&panel=center" id="leftNav" class="navlink"><i class="icon-previous icon-large white"></i></a>
<a href="?cat=<div style=&panel=left" id="rightNav" class="navlink"><i class="icon-next icon-large white"></i></a>
<script type="text/javascript">
$(document).ready(function() {
$('body').append('<div id="loaded_page"></div>');
url = $('#leftNav').attr('href')
$.ajax({
url: url,
success: function(data){
data = data.replace(/<script.*?<\/sc/mgi,'');
alert(data);
},
dataType: 'html'
});
return;
</script>
....................
所以我需要結果爲
.....</div><!-- end header -->
<div id="snapshot">
<a href="?cat=<div style=&panel=center" id="leftNav" class="navlink"><i class="icon-previous icon-large white"></i></a>
<a href="?cat=<div style=&panel=left" id="rightNav" class="navlink"><i class="icon-next icon-large white"></i></a>
所有javascript都應該被剪切。正則表達式替換data.replace(/<script.*?<\/sc/mg,'')
事情是在一個行僅
和正則表達式所需的數據格式是什麼? – 2012-03-29 12:53:02
正則表達式不起作用,它應該用'' – 2012-03-29 12:56:28