TinyMCE没有初始化,但是没有JavaScript错误

TinyMCE not initializing, but no JavaScript errors

本文关键字:JavaScript 错误 初始化 TinyMCE      更新时间:2023-09-26

我有一个非常简单的电子邮件表单(用于私人俱乐部的会员专属页面)发送电子邮件。代码很简单:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="../../../tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
</head>
<body>
<h1>Email Blast</h1>
<form method="post">
<input type="hidden" name="from" value="blast@club.com" />
<input type="hidden" name="to" value="blast@club.com" />
<input type="hidden" name="reply" value="from@club.com" />
<input type="hidden" name="bcc" value="Tester <test@club.com>" />
<label for="subject">Subject</label><br/>
<input type="text" name="subject" id="subject" style="width: 600px" /><br/>
<label for="message">Message</label><br/>
<textarea id="message" name="message" rows="15" cols="100" class="tinymce"></textarea><br/>
<br/><input type="submit" value="Send Email" name="submit">
</form>
</body>
<script type="text/javascript">
jQuery(document).ready(function() {
    tinymce.init({selector:"textarea.tinymce"});
});
</script>

由于某种原因,页面根本没有像我期望的那样呈现textarea.tinymce,但是在JS控制台中没有错误消息,并且所有的断点都像我期望的那样被击中。

我错过了什么?

你应该把你的script标签在body标签内,就在关闭它之前。

如果您在关闭body标记后放置任何内容,浏览器将忽略它。

看下面的例子——如果你把script标签放在body标签里面,它就像一个魅力:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/4.2.5/tinymce.jquery.min.js"></script>
</head>
<body>
<h1>Email Blast</h1>
<form method="post">
<input type="hidden" name="from" value="blast@club.com" />
<input type="hidden" name="to" value="blast@club.com" />
<input type="hidden" name="reply" value="from@club.com" />
<input type="hidden" name="bcc" value="Tester <test@club.com>" />
<label for="subject">Subject</label><br/>
<input type="text" name="subject" id="subject" style="width: 600px" /><br/>
<label for="message">Message</label><br/>
<textarea id="message" name="message" rows="15" cols="100" class="tinymce"></textarea><br/>
<br/><input type="submit" value="Send Email" name="submit">
</form>
<script type="text/javascript">
jQuery(document).ready(function() {
    tinymce.init({selector:"textarea.tinymce"});
});
</script>
</body>
</html>