如何从 textarea ckeditor 获取值

how to get value from textarea ckeditor

我是ckeditor的新手,目前正在写ckeditor的演示代码。有人可以帮助我如何从 textarea ckeditor 中获取价值。下面是我的代码

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>CKEditor 4</title>
</head>

<body>
    <textarea id="idDemo" name="demo"></textarea>
    <input type="button" value="Get Data" onclick="myFunction()" />
    <script>
        function myFunction() {
            var content = $('idDemo').val();
            alert(content);
        }
    </script>

    <script src="ckeditor/ckeditor.js"></script>
    <script>CKEDITOR.replace('demo');</script>
</body>

</html>

根据 documentation,这应该可以解决问题。

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>CKEditor 4</title>
</head>

<body>
    <textarea id="idDemo" name="demo"></textarea>
    <input type="button" value="Get Data" onclick="myFunction()" />
    <script>
        function myFunction() {
            var content= CKEDITOR.instances.editor1.getData();
            alert(content);
        }
    </script>

    <script src="ckeditor/ckeditor.js"></script>
    <script>CKEDITOR.replace('demo');</script>
</body>

</html>