我正则不熟 只能到这程度<div contentEditable id=div onkeyup="edit(this.innerHTML)">edit</div>
<div id=r ></div>
<input type="button" value="查看代码" onclick="alert(document.getElementById('div').innerHTML)">
<SCRIPT LANGUAGE="JavaScript">
function edit(html)
{
html = html.replace(/<P>/g,"");
html = html.replace(/<\/P>/g,"<br/>");
document.getElementById('div').innerHTML=html;
}
</SCRIPT>
<div id=r ></div>
<input type="button" value="查看代码" onclick="alert(document.getElementById('div').innerHTML)">
<SCRIPT LANGUAGE="JavaScript">
function edit(html)
{
html = html.replace(/<P>/g,"");
html = html.replace(/<\/P>/g,"<br/>");
document.getElementById('div').innerHTML=html;
}
</SCRIPT>
<div id=r ></div>
<input type="button" value="查看代码" onclick="alert(document.getElementById('div').innerHTML)">
<SCRIPT LANGUAGE="JavaScript">
function edit(html)
{
if(event.keyCode==13){
var textRange=document.selection.createRange();
textRange.text="\r\n";
textRange.select();
event.returnValue=false;
}
}
</SCRIPT>
这样,就可以解决回车换行时,两行相隔很远.而不用将<p>替换为<br/>