How do I get the contents from dijit/Editor?

五迷三道 提交于 2019-12-11 05:43:48

问题


I want to use dijit/Editor to allow users to enter formatted text on a form. The documentation is here. I set up a div on my form and added attributes for the HTML Editor.

<label for="eed-event-description" class="required">Event Description</label><br />
<div id="eed-event-description" data-dojo-type="dijit/Editor" height="120px" title="required: brief description of what someone attending can expect at the event" required>
    <p></p>
</div>

This results in a lot of new code, including an iframe:

<iframe id="eed-event-description_iframe" style="border: medium none; width: 100%; height: 120px;" title="Event Description" src="javascript: '<!DOCTYPE html><html lang=\'en\'>
<head>
<meta http-equiv=\'Content-Type\' content=\'text/html\'>
<title>Event Description</title><style>
    body,html {
        background:transparent;
        padding: 1px 0 0 0;
        margin: -1px 0 0 0;
    }
    body,html,#dijitEditorBody { outline: none; }html { height: 100%; width: 100%; overflow: hidden; }
    body,#dijitEditorBody { height: 100%; width: 100%; overflow: auto; }
    body{
        top:0px;
        left:0px;
        right:0px;
        font:400 16px &quot;Lucida Sans Unicode&quot;, Arial, Helvetica, sans-serif;
        line-height:1.125;
    }
    p{ margin: 1em 0; }
    li > ul:-moz-first-node, li > ol:-moz-first-node{ padding-top: 1.2em; }
    li{ min-height:1.2em; }
</style>

</head>
<body role=\'application\' aria-label=\'Event Description\'onload=\'try{frameElement &amp;&amp; frameElement._loadFunc(window,document)}catch(e){document.domain=&quot;id0129.vps.sonic.net&quot;;frameElement._loadFunc(window,document)}\' style=\'\'><div id=\'dijitEditorBody\' role=\'textbox\' aria-multiline=\'true\'  aria-label=\'Event Description\'></div></body>
</html>'" class="dijitEditorIFrame" frameborder="0"></iframe>

I don't know how to reference the area where the user adds text, and I don't see any documentation on dojotoolkit.org that tells me how to pick up the results in JavaScript to process. How do I get this text ?


回答1:


The dijit/Editor has the .get('value') method in order to get it's HTML area content ,

So you can simply get a reference of your dijit by using dijit/registry and the use the function .

var myEditor = registry.byId("eed-event-description");
var htmlValue = myEditor.get('value');

See this Fiddle for demo



来源:https://stackoverflow.com/questions/50502222/how-do-i-get-the-contents-from-dijit-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!