继承自特定的html代码,其中包含按钮'bold'和文本区域。在文本区域中将文本设置为粗体
<form name="myform">
< input type="button" onClick="Bold()" value="Bold">
</form>
<textarea name="myTextArea" id="myTextArea" cols="100" rows="14" placeholder="Enter Text Here ...">< /textarea>
下面有我的JavaScript
function Bold() {
myTextArea.document.execCommand('bold',false,null);
}
什么我做错了????
你能解释一下什么是这个代码'myTextArea.document.execCommand('bold',false,null);'? –
你也可以使用它,如果你想要更多的功能,如粗体,斜体等http://ckeditor.com/demo – Ashish
首先,我认为这是行不通的,因为JavaScript不识别'myTextArea'作为HTML元素。你可以使用类似'jQuery'的库来轻松识别元素。其次,正如@Pilot所说,我不知道'.document.execCommand('bold',false,null)是什么。你从哪里拿到这些代码? –