问题
Have been working on this error for 2 days and cannot get TinyMCE to work. I am using the jquery version of TinyMCE. Below is my HTML code with a form that contains a textarea. I use Google Inspect Element and under the console tab i get the following error: "Uncaught ReferenceError: tinymce is not defined". Any help would be appreciated.
<form id="add_update_form" action="" method="POST" title="Add Blog">
<p class="feedback"></p>
<!-- <label>Created:</label>
<input type="text" name="created"> -->
<label>Title:</label>
<input type="text" name="title" class="input-block-level">
<label>Content:</label>
<textarea width="100%" rows="10" cols="10" name="content" class="input-block-level"></textarea>
<div class="clear"></div>
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script src="<?php echo base_url();?>js/portal/tinymce/jquery.tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector: "textarea",
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste moxiemanager"
],
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});
</script>
回答1:
As you are using the jquery version you'll need to set it up like a jquery plugin
$(function() {
$('textarea.tinymce').tinymce({
...
});
});
http://www.tinymce.com/tryit/3_x/jquery_plugin.php
回答2:
I looked at this page: http://www.tinymce.com/tryit/3_x/jquery_plugin.php and clicked tab "View source" and noticed something.
If you are using TinyMCE as jQuery plugin, there is additional parameter required script_url, so your code should look like this:
$('textarea.tinymce').tinymce({
script_url: 'js/portal/tinymce/tinymce.min.js',
...
Other solution is to use non-jQuery version:
<script src="<?php echo base_url();?>js/portal/tinymce/tinymce.min.js"></script>
and then use old method to init the TinyMCE (as in your initial code):
tinymce.init({
selector: "textarea",
...
回答3:
It seems that TinyMCE js file is not loaded. Instead of:
<script src="<?php echo base_url();?>js/portal/tinymce/jquery.tinymce.min.js"></script>
Try the following:
<script src="//cdn.jsdelivr.net/tinymce/4.0b2/jquery/jquery.tinymce.min.js" type="text/javascript"></script>
来源:https://stackoverflow.com/questions/16907580/tinymce-is-not-defined-jquery