嘿,我試圖取代在JavaScript換行符替換不工作:(
<blockquote>...</blockquote>
與
>> ...
這是我的代碼:
var testhtml = 'sdkjhfbs <blockquote>skldfjsfkjghbs\n sdjkfhb ksdbhv isl\n kdjbhdfgkj bs</blockquote>kdjfgnkdfj';
alert(blockquoteConvert(testhtml));
function blockquoteConvert(html) {
return '>>' + html.
replace(/<blockquote>([^]+)<\/blockquote>/gi,"$1").
replace('/\n/','\n>> ');
}
但它沒有找到Linebreaks(我用indexOf('\ n')查過)
我該怎麼做?
和RegExp對象也會。 ''abc \ ndef'.replace(new RegExp('\\ n','g'),'\ n >>')' – ZJR 2010-01-10 15:13:57