私はこの問題と同様の質問を読んでいて、かなり遠くまで行くことができましたが、明らかに私の状況は少し異なるので、まだこれを理解しようとしています.
Tinymce html エディターでスタイル設定されたテキストエリアを持つフォームがあります。テキストエリアをAJAXで自動保存したいです。
時間間隔に基づいてテキストエリアを保存するコードを使用しています。
$(document).ready(function() {
$(function() {
// Here we have the auto_save() function run every 30 secs
// We also pass the argument 'editor_id' which is the ID for the textarea tag
setInterval("auto_save('editor_id')",30000);
});
});
// Here is the auto_save() function that will be called every 30 secs
function auto_save(editor_id) {
// First we check if any changes have been made to the editor window
if(tinyMCE.getInstanceById(editor_id).isDirty()) {
// If so, then we start the auto-save process
// First we get the content in the editor window and make it URL friendly
var content = tinyMCE.get(editor_id);
var notDirty = tinyMCE.get(editor_id);
content = escape(content.getContent());
content = content.replace("+", "%2B");
content = content.replace("/", "%2F");
// We then start our jQuery AJAX function
$.ajax({
url: "PAFormAJAX.asp", // the path/name that will process our request
type: "POST",
data: "itemValue=" + content,
success: function(msg) {
alert(msg);
// Here we reset the editor's changed (dirty) status
// This prevents the editor from performing another auto-save
// until more changes are made
notDirty.isNotDirty = true;
}
});
// If nothing has changed, don't do anything
} else {
return false;
}
}
これは機能していますが、私の問題は、フォーム要素が動的に作成されるため、使用できる静的な editor_id が常にあるとは限らないことです。動的 ID を受け入れるように更新するにはどうすればよいですか?
たとえば、ASP で動的に ID が設定されているテキストエリアの 1 つを次に示します。
<textarea id="Com<%=QuesID%>" row= "1" cols= "120" name="Com<%=QuesID%>" QuesID="<%=QuesID%>" wrap tabindex="21" rows="10" class="formTxt"><%=TempTxt%></textarea>
また、時間間隔で保存機能を呼び出すだけでなく、ユーザーがテキストエリアをクリックしてフォーカスを失ったときにも呼び出す方法を見つけようとしています。TinyMce は明らかにテキストエリアから iframe に変更するため、これを行う方法がわかりません。
どんな助けでも大歓迎です。