[英]Creating My WYSIWYG Editor - JavaScript Strange Behaviour
I'm working on my on Visual Text editor. 我正在使用可视文本编辑器。 It's working decently, preview works perfectly, and so does my JS appending.
它工作得很好,预览效果很好,我的JS追加也是如此。 The HTML is this one:
HTML是这样的:
<div class="wysiwyg">
<div class="wystitle">What You See Is What You Get<br>Editor by ShowTime</div>
<div class="wysmenu"><button class="wysbutton" onClick="addBold()">Bold</button><button class="wysbutton">Italic</button><button class="wysbutton">Underline</button><button class="wysbutton">Link</button><button class="wysbutton">Color</button><button class="wysbutton">Quote</button></</div>
<textarea rows="9" cols="145" id="wystext"></textarea><br>
<button class="wysbutton" onClick="preview()">Preview</button><button class="wysbutton">Post!</button>
</div>
<br><br><br><br><br><br><br><br><br><br><br>
<div class="wyspreview" id="wyspreview">Hit 'Preview' To See the Post General Look<br>Hit 'Post' To Create the Blog Post</div>
And I want to have the Bold button to simply add TEXT HERE . 而且我想使用粗体按钮来简单地添加TEXT HERE 。 This is the JAvaScript:
这是JAvaScript:
function preview() {
var preview = document.getElementById("wystext").value;
document.getElementById("wyspreview").innerHTML = preview;
}
function addBold() {
var text = document.getElementById("wystext").value;
document.getElementById("wystext").innerHTML = text + "<strong></strong>";
var text = null;
}
The addBold function works properly, but as soon as I type in the text area, it won't work anymore. addBold函数可以正常工作,但是一旦我在文本区域中键入,它将不再起作用。 Any ideas why ?
有什么想法吗?
Nevermind, found a fix, just edited innerHTML
to value
. 没关系,找到了解决方法,只是将
innerHTML
编辑为value
。
Might come helpfull for some users. 对某些用户可能会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.