SJ1*_*J11 6 dojo jsp form-submit rich-text-editor
我正在努力学习dijit编辑器.我想用dijit编辑器widget替换现有的文本区域.所以我写了2个jsps - 一个使用dijit.Editor,它用编辑器内容提供另一个jsp.当我单击提交时,无论在文本区域编辑器中输入什么内容,第二个jsp "结果 "都会出现编辑器的空内容.
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
而不是将其绑定到表单onsubmit,尝试通过小部件进行onChange
给你的隐藏字段一个id:
<input type="hidden" name="editorContent" id='editorContent' />
Run Code Online (Sandbox Code Playgroud)
尝试使用编辑器onChange(替换console.log()现在的代码).
onChange="dojo.byId('editorContent').value = this.getValue();"
Run Code Online (Sandbox Code Playgroud)
等待!当我输入这个时,我意识到你正在调用dojo.byId('editorContent')你的onsubmit但你还没有将id属性分配给那个表单字段.这可能是你的问题,你不需要尝试我的onChange方法.
| 归档时间: |
|
| 查看次数: |
3415 次 |
| 最近记录: |