我正在尝试学习 dijit 编辑器。我想用 dijit 编辑器小部件替换现有的文本区域。所以我写了 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>
结果.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>
最佳答案
而不是将其绑定(bind)到表单的 onsubmit
,尝试通过小部件的 onChange
进行操作
给你的隐藏字段一个 id:
<input type="hidden" name="editorContent" id='editorContent' />
试试这个编辑器的
onChange
(替换您现在拥有的 console.log()
代码。onChange="dojo.byId('editorContent').value = this.getValue();"
等待! 当我输入这个时,我意识到您正在调用
dojo.byId('editorContent')
在您的 onsubmit
但您尚未分配 id
属性到该表单字段。这可能是您的问题,您无需尝试我的 onChange
方法。
关于jsp - 提交 dijit 编辑器内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6695581/