在线文本编辑器中,如何实现的对选定的内容加HTML代码?
我能找出被选中的内容
我想实现的是
选择一部分内容,然后点按钮(例如加粗),实现对那段文字的操作(结果是那段文字加粗了,但是其他文件依然保持原样)
text.htm
<body canHaveHTML="true">
</body>
edit.htm
<table width="500">
<tr>
<td>
<input type="button" value="加粗" onclick="jiacu()">
</td>
<td>
<input type="button" value="获得信息" onclick="alert(tempframe.document.getElementsByTagName('BODY')[0].innerText)">
</td>
<td>
<input type="button" value="获得选中的信息" onclick="alert(tempframe.document.getElementsByTagName('BODY')[0].document.selection.createRange().htmlText)">
</td>
</tr>
<tr>
<td colspan="3">
<iframe src="text.htm" id="tempframe" name="tempframe" width="800" scrolling="yes"></iframe>
<script language="javascript">
window.frames["tempframe"].document.designMode="On";
</script>
</td>
</tr>
</table>
<script>
function jiacu()
{
tempframe.document.getElementsByTagName('BODY')[0].innerHTML="<strong>"+tempframe.document.getElementsByTagName('BODY')[0].innerHTML+"</strong>"
}
</script>
我只能实现全部加粗,不知道局部加粗怎么弄