You could create a function like this:
jQuery.fn.nl2br = function(){
return this.each(function(){
jQuery(this).val().replace(/(<br>)|(<br />)|(<p>)|(</p>)/g, "
");
});
};
And use it like any of these ways:
$(':input').nl2br();
$('textarea').nl2br();
$('#textarea_id').nl2br();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…