ckeditorの設置時、変なエラー「Uncaught TypeError: Cannot call method 'getEditor」原因は・・
ckeditorの最新版を久々にいじってます。
いつも慣れ親しんでいるckeditor、いつも通りに設置してみると、、
エラー!
最初に書いたソースはこれ
classで指定すればちゃんと出来るし、、
でも1ページに複数のckeditorを設置したい時、これじゃ困ります。
原因はとっても簡単でした。
textareaよりも後にckeditorのreplaceメソッドを指定すればOK
いつも慣れ親しんでいるckeditor、いつも通りに設置してみると、、
エラー!
Uncaught TypeError: Cannot call method 'getEditor' of undefined
最初に書いたソースはこれ
<html>
<head>
<title>ckeditor</title>
<script src="/ckeditor/ckeditor.js"></script>
<script>
CKEDITOR.replace( 'editor1');
</script>
</head>
<body>
<textarea name="editor1" id="editor1" rows="10" cols="80"></textarea>
</body>
</html>
最初はまったくわかならくて、、、<head>
<title>ckeditor</title>
<script src="/ckeditor/ckeditor.js"></script>
<script>
CKEDITOR.replace( 'editor1');
</script>
</head>
<body>
<textarea name="editor1" id="editor1" rows="10" cols="80"></textarea>
</body>
</html>
classで指定すればちゃんと出来るし、、
<html>
<head>
<title>ckeditor</title>
<script src="/ckeditor/ckeditor.js"></script>
</head>
<body>
<textarea name="editor1" class="ckeditor" rows="10" cols="80"></textarea>
</body>
</html>
※ classにckeditorと指定すればOK<head>
<title>ckeditor</title>
<script src="/ckeditor/ckeditor.js"></script>
</head>
<body>
<textarea name="editor1" class="ckeditor" rows="10" cols="80"></textarea>
</body>
</html>
でも1ページに複数のckeditorを設置したい時、これじゃ困ります。
原因はとっても簡単でした。
textareaよりも後にckeditorのreplaceメソッドを指定すればOK
<html>
<head>
<title>ckeditor</title>
<script src="/ckeditor/ckeditor.js"></script>
</head>
<body>
<textarea name="editor1" id="editor1" rows="10" cols="80"></textarea>
<script>
CKEDITOR.replace( 'editor1');
</script>
</body>
</html>
きちんとエラーメッセージを読めばわかりますね。英語だからって思考停止しちゃダメ、、反省です。
<head>
<title>ckeditor</title>
<script src="/ckeditor/ckeditor.js"></script>
</head>
<body>
<textarea name="editor1" id="editor1" rows="10" cols="80"></textarea>
<script>
CKEDITOR.replace( 'editor1');
</script>
</body>
</html>
スポンサーサイト
コメント
コメントの投稿
« ckeditorのunderlineボタンが出ないよー (config.jsに、、、) l Home l PHPが凄く重い・・・原因はライブラリ多すぎ »