我想包括一个WYSIWYG编辑器在一个网页,正在设计。我偶然发现了bootstrap-wysihtml5。从外观上看,这正是我想要的(简单而优雅)。我想看一个例子,但是没有很多好的例子来说明如何设置它。到目前为止,我已经这样做了:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Editor</title>
<link rel="stylesheet" type="text/css" media="screen" href="bootstrap-wysihtml5.css"/>
<script src = "bootstrap-wysihtml5.js" type = "text/javascript"></script>
<script src = "wysihtml5-0.3.0.min.js" type = "text/javascript"></script>
<script src = "bootstrap.min.js" type = "text/javascript"></script>
</head>
<body>
<textarea class="textarea" id="ta1" placeholder="Enter text ..." style="width: 810px; height: 200px">
</textarea>
<script>$(".textarea").wysihtml5();</script>
<body>
</html>以下是chrome控制台中的错误:
Uncaught TypeError: Cannot read property 'fn' of undefined bootstrap-wysihtml5.js:368
Uncaught TypeError: undefined is not a function bootstrap.min.js:6
Uncaught TypeError: Object [object Object] has no method 'wysihtml5' editor.html:14我不知道如何解决这些错误,你认为哪里出了问题?
谢谢。
发布于 2013-04-18 18:46:05
您需要包含jQuery才能正常工作,作为本例中的第一个脚本元素。
Bootstrap高度依赖于jQuery,也许"wysihtml5“插件也是如此,所以在这些插件之前必须包含jQuery。
您甚至可以通过错误日志看到这一点:
第一个提示是fn
Uncaught TypeError: Cannot read property 'fn' of undefined fn基本上就是prototype -- jQuery的“包装器”,bootstrap试图在这一行的jQuery原型中添加一些东西。
第二个提示:
Uncaught TypeError: Object [object Object] has no method 'wysihtml5' 默认情况下,$被绑定到Chrome中的选择器函数,所以它返回一个普通的HTML元素,而不是本例中的jQuery对象。wysihtml5很可能会将自己绑定到jQuery - prototype上,因此可以用这种方式在jQuery-elements上调用它。当jQuery不存在时,您会尝试调用一个在本例中不存在的普通Object的函数。
https://stackoverflow.com/questions/16079406
复制相似问题