问题
I have a textarea to which I associate a Rich Text Editor. I've followed the steps to install it and everything runs smoothly. The textarea in question is within a form with other textarea and fields to be filled out. Clicking on the classic submit button, I set via js that if the field is empty an alert appears and the system puts the focus on the empty element.
This does not work with the textarea combined with the Rich Text Editor, obviously because the latter transforms it into a sort of frame ...
I use CLEditor WYSIWYG Editor
as an 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>
I've tried to solve my problem in a few different ways, for example:
function checkForm(form) {
if(form.nomexf.value == "") {
alert("Il campo Titolo non è stato compilato!");
$("#nomexf").cleditor().focus();
return false;
}
}
However, I am still struggling to make it work.
回答1:
cleditor()
returns an array so you have to specify which textarea you want:
try this:
$('#nomexf').cleditor()[0].focus();
来源:https://stackoverflow.com/questions/52081137/rich-text-editor-and-focus-by-submit-button