提交dijit编辑器内容 [英] Submit the dijit editor contents
问题描述
当我点击提交时,第二个jsp result 出现编辑器的空白内容,无论文本区域编辑器中输入什么。
dijitEditor.jsp
< script type =text / javascript>
dojo.require(dijit.Editor);
dojo.require(dijit._editor.plugins.LinkDialog);
dojo.require(dijit._editor.plugins.AlwaysShowToolbar);
< / script>
< script type =text / javascript>
dojo.addOnLoad(function(){
alert(addOnLoad function);
dojo.connect(dojo.byId('form1'),'onsubmit',function(){
dojo.byId('editorContent')。value = dijit.byId('content')。getValue();
alert(Hidden variable);
alert(dojo.byId编辑器内容')
alert(Editor content);
alert(dijit.byId('content')。getValue());
});
});
< / script>
< link rel =stylesheettype =text / csshref =http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css />
< / head>
< body class =claro>
< FORM id =form1METHOD = POST ACTION =result.jsp>
< table>
< tr>
< td>
< input type =hiddenname =editorContent/>
< div dojoType =dijit.Editorid =contentonChange =console.log('editor1 onChange handler:'+ arguments [0])
plugins =['foreColor' ,'|','bold','italic','underline','|','createLink','unlink']
extraPlugins =['dijit._editor.plugins.AlwaysShowToolbar']> ;
< p>
< b>此实例是使用我们想要的顺序
启用的功能子集创建的。 < / B个
< / p>
< / div>
< / td>
< / tr>
< tr>
< td>
< input type =submitvalue =Submitname =action/>
< / td>
< / tr>
< / table>
< / form>
< / body>
< / html>
result.jsp
<!DOCTYPE HTML PUBLIC - // W3C // DTD HTML 4.01 // ENhttp://www.w3.org/TR/html4/strict。 DTD>
< html>
< head>
< title>编辑内容< / title>
< / head>
< body>
<%
String val = request.getParameter(editorContent);
out.println(Dijit editor contents =+ val);
%>
< / body>
< / html>
而不是将其绑定到窗体的 onsubmit
,尝试通过小部件的 onChange
提供隐藏的字段一个id:
< input type =hiddenname =editorContentid ='editorContent'/>
为编辑器的 onChange
(替换
onChange =dojo.byId('editorContent')。value = this.getValue();
等待!当我输入此字段时,我意识到您正在调用 dojo.byId('editorContent')
在您的 onsubmit
中,但您尚未将 id分配给该表单字段,这可能是您的问题,您需要尝试我的
onChange
方法。
I am trying to learn the dijit editor. I want to replace an existing text area with dijit editor widget.So I wrote 2 jsps - one using the dijit.Editor which feeds another jsp with the editor contents. When I click submit the second jsp "result" comes up empty contents for the editor no matter what is typed in text area editor.
dijitEditor.jsp
<script type="text/javascript">
dojo.require("dijit.Editor");
dojo.require("dijit._editor.plugins.LinkDialog");
dojo.require("dijit._editor.plugins.AlwaysShowToolbar");
</script>
<script type="text/javascript">
dojo.addOnLoad(function(){
alert("addOnLoad function");
dojo.connect(dojo.byId('form1'), 'onsubmit', function(){
dojo.byId('editorContent').value= dijit.byId('content').getValue();
alert("Hidden variable");
alert(dojo.byId('editorContent').value);
alert("Editor content");
alert(dijit.byId('content').getValue());
});
});
</script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css" />
</head>
<body class=" claro ">
<FORM id="form1" METHOD=POST ACTION="result.jsp">
<table>
<tr>
<td>
<input type="hidden" name="editorContent" />
<div dojoType="dijit.Editor" id="content" onChange="console.log('editor1 onChange handler: ' + arguments[0])"
plugins="['foreColor','|','bold','italic','underline','|','createLink', 'unlink']"
extraPlugins="['dijit._editor.plugins.AlwaysShowToolbar']">
<p>
<b>This instance is created with a subset of functions enabled in the order
we want. </b>
</p>
</div>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Submit" name="action"/>
</td>
</tr>
</table>
</form>
</body>
</html>
result.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html >
<head>
<title>Editor contents </title>
</head>
<body>
<%
String val = request.getParameter("editorContent");
out.println("Dijit editor contents ="+val);
%>
</body>
</html>
Instead of binding it to the form's onsubmit
, try doing it via the widget's onChange
Give your hidden field an id:
<input type="hidden" name="editorContent" id='editorContent' />
Try this for the Editor's onChange
(replacing the console.log()
code you have there now.
onChange="dojo.byId('editorContent').value = this.getValue();"
Wait! As I was typing this I realized you are calling dojo.byId('editorContent')
in your onsubmit
but you have not assigned the id
attribute to that form field. That's probably your issue and you needn't try my onChange
method.
这篇关于提交dijit编辑器内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!