Rich Text Editor and focus by submit button

送分小仙女□ 提交于 2019-12-11 09:14:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!