问题
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 "Lucida Sans Unicode", 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 && frameElement._loadFunc(window,document)}catch(e){document.domain="id0129.vps.sonic.net";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