您鏈接到的小提琴沒有工作,因爲它調用最新的TinyMCE JavaScript庫。我改成了使用TinyMCE的v.3.5.11:
http://fiddle.tinymce.com/Cnfaab
撥動格式現在的作品。
<a class="btn" href="javascript:;" onclick="tinymce.execCommand('mceToggleEditor',false,'content');"><span>Toggle TinyMCE</span></a>
在TinyMCE4:
不知道這是正確的方式,但我相信這不會你想要做什麼: http://codepen.io/anon/pen/ZQXLBo
JS:
tinymce.init({
selector: 'textarea',
height: 500,
toolbar: 'mybutton',
menubar: false,
setup: function(editor) {
editor.addButton('mybutton', {
text: 'My button',
icon: false,
onclick: function(e) {
var $ = tinymce.dom.DomQuery;
var myTextarea = $('textarea');
var myIframe = $(editor.iframeElement);
myTextarea.value = editor.getContent({
source_view: true
});
myIframe.toggleClass("hidden");
myTextarea.toggleClass("visible");
if ($('iframe.hidden').length > 0) {
myTextarea.prependTo(".mce-edit-area");
} else {
myIframe.value = myTextarea.value;
myTextarea.appendTo('body');
}
}
});
},
content_css: [
'//fast.fonts.net/cssapi/e6dc9b99-64fe-4292-ad98-6974f93cd2a2.css',
'//www.tinymce.com/css/codepen.min.css'
]
});
HTML:
<textarea>
<p style="text-align: center; font-size: 15px;"><img title="TinyMCE Logo" src="//www.tinymce.com/images/[email protected]" alt="TinyMCE Logo" width="110" height="97" />
</p>
<h1 style="text-align: center;">Welcome to the TinyMCE editor demo!</h1>
<p>Select a menu item from the listbox above and it will insert contents into the editor at the caret position.</p>
<h2>Got questions or need help?</h2>
<ul>
<li>Our <a href="http://www.tinymce.com/docs/">documentation</a> is a great resource for learning how to configure TinyMCE.</li>
<li>Have a specific question? Visit the <a href="http://community.tinymce.com/forum/">Community Forum</a>.</li>
<li>We also offer enterprise grade support as part of <a href="http://www.tinymce.com/pricing">TinyMCE Enterprise</a>.</li>
</ul>
<h2>Found a bug?</h2>
<p>If you think you have found a bug please create an issue on the <a href="https://github.com/tinymce/tinymce/issues">GitHub repo</a> to report it to the developers.</p>
<h2>Finally ...</h2>
<p>Don't forget to check out our other product <a href="http://www.plupload.com" target="_blank">Plupload</a>, your ultimate upload solution featuring HTML5 upload support.</p>
<p>Thanks for supporting TinyMCE! We hope it helps you and your users create great content.
<br>All the best from the TinyMCE team.</p>
</textarea>
CSS:
textarea {
height: 500px !important;
width: 100% !important;
position: absolute;
z-index: 100;
}
.hidden {
visibility: hidden !important;
display: none !important;
}
.visible {
visibility: visible !important;
display: block !important;
}
有沒有辦法用最新的TinyMCE做到這一點? –
應該可行。我明天會看。就像在TinyMCE 4中一樣,大多數人使用[「code」插件](https://www.tinymce.com/docs/plugins/code/)。 – medinasod
我更新了我在TinyMCE 4中工作的答案。 – medinasod