我试图在文本框中将所选文本格式化为粗体但不会发生。但是,这是一个跨度/格。我的代码在文本框中设置文本的格式
<html>
<head>
<title>Untitled Document</title>
<script type="text/javascript">
function FormatSelectedWord(txtBox,style)
{
var selectedText = document.selection
? document.selection.createRange().text
: txtBox.value.substring(txtBox.selectionStart,txtBox.selectionEnd);
if(selectedText!='')
{
var newText='<'+style+'>'+selectedText+'</'+style+'>';
txtBox.value=txtBox.value.replace(selectedText,newText)
spOutput.innerHTML=txtBox.value;
}
}
</script>
</head>
<body>
<input type="text" name="txtBox"> </input>
<input type="button" value="Bold" onclick="FormatSelectedWord(txtBox,'b')">
<span id="spOutput"></span>
</body>
</html>
是否可以在insde文本框中执行此操作。如果是这样如何?
感谢
我怎么从来不知道这个? – Marcel