我有一个与 Rich Text Editor 相关联的文本区域。我已经按照步骤安装它,并且一切运行顺利。有问题的文本区域在一个表单中,其中包含其他文本区域和要填写的字段。单击经典的提交按钮,我通过js进行了设置,如果该字段为空,则会出现警报,并且系统会将焦点放在空元素上。
这不适用于与富文本编辑器结合使用的文本区域,显然是因为后者将其转换为一种框架...
我使用CLEditor WYSIWYG Editor
作为编辑器:
<html>
<head>
<link rel="stylesheet" href="jquery.cleditor.css" />
<script src="jquery.min.js"></script>
<script src="jquery.cleditor.min.js"></script>
<script>
$(document).ready(function () { $("#nomexf").cleditor(); });
</script>
</head>
<body>
<textarea id="nomexf" name="nomexf"></textarea>
</body>
</html>
我试图以几种不同的方式解决我的问题,例如:
function checkForm(form) {
if(form.nomexf.value == "") {
alert("Il campo Titolo non è stato compilato!");
$("#nomexf").cleditor().focus();
return false;
}
}
但是,我仍然在努力使其工作。
答案 0 :(得分:0)
cleditor()
返回一个数组,因此您必须指定所需的文本区域:
尝试一下:
$('#nomexf').cleditor()[0].focus();