简体   繁体   中英

how to get value from textarea ckeditor

I am new to ckeditor, at moment I am writting a demo code on ckeditor. Could someone please help me how to get value from texterea ckeditor. Here below is my code

<!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>

According to the documentation , this should do the trick.

<!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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM