我想製作一個自定義文本stylizer thingy ...因此,如果用戶在textarea中編寫文本並選擇其中的一部分,他將能夠使用我的自定義「後期設計師」按鈕。就像這裏,在Stackoverflow中。可能有人幫助我,我發現在這個論壇上沒什麼......用jQuery更改textarea中的選定文本
HTML
<div id="makeItBold" style="cursor: pointer;">B</div>
<textarea id="text">I'm going to make THIS bold!</textarea>
JQUERY
$(document).ready(function() {
$("#makeItBold").click(function() {
if ($(this.selected).text().contains "<b>" or "</b>"){
//if the selected text is already bolded, then remove it
???
} else {
//make it bold
???
$(this.selected).text().replace(this.selected, "<b>" + this.selected + "</b>");
}
});
});
所以,你想建立一個WYSIWG編輯器?像[this](http://ckeditor.com/download)一樣? – empiric