0

私は wysihtml5Editor を持っていますが、jQuery を使用してエディターの値をクリアしたいと考えています。私は次のようにコードを書きました:

$(function () {
   $("#cleartext").live('click', function () {
    $('#def_text').wysihtml5().data("wysihtml5").editor.clear();
    });
});

<textarea  name="def_text"  id="def_text" class="w100" rows="9" cols="50" data-bind="editor: def_text"></textarea>
<button type="reset" class="btn" id="cleartext"><i class="icon-pencil"></i> New Contract</button>

目的の結果が得られません。エディターが定義されていないというエラーが表示されます。提案してください。

4

7 に答える 7

3

複雑にしすぎていると思います。変数を設定してテキストエリアにリンクするだけで、変数のみを使用できます。

var editor = new wysihtml5.Editor("myTextarea");
editor.clear();

また

editor.setValue('', true);

私のために働いた。

于 2013-04-09T15:43:35.677 に答える
0

これは私にとってはうまくいきました。、divタグを作成し、内部にテキストエリア要素を入れます

<div id="CommentTextArea">

<textarea  name="comment_text"  id="comment"  rows="9" cols="50" ></textarea>

</div>

<button type="submit"  id="send"> Send </button>

.js ファイル内

 $(function(){

// Initialize the Editor
$("#comment").wysihtml5({

toolbar: {
 "size": "xs",    //<buttonsize> // options are xs, sm, lg
"font-styles": false, // Font styling, e.g. h1, h2, etc.
"emphasis": true, // Italics, bold, etc.
"lists": false, // (Un)ordered lists, e.g. Bullets, Numbers.
"html": false, // Button which allows you to edit the generated HTML.
"link": true, // Button to insert a link.
"image": true, // Button to insert an image.
"color": false, // Button to change color of font
"blockquote": false, // Blockquote

}
});

// when the send button is clicked

$('#send').click(function(){

   setTimeout(function(){
        //remove  wysihtml5Editor contents  
   $("#CommentTextArea").html('<textarea  name="comment_text"  id="comment"  rows="9" cols="50" ></textarea>');

// and then Initialize the Editor again,

$("#comment").wysihtml5({

toolbar: {
 "size": "xs",    //<buttonsize> // options are xs, sm, lg
"font-styles": false, // Font styling, e.g. h1, h2, etc.
"emphasis": true, // Italics, bold, etc.
"lists": false, // (Un)ordered lists, e.g. Bullets, Numbers.
"html": false, // Button which allows you to edit the generated HTML.
"link": true, // Button to insert a link.
"image": true, // Button to insert an image.
"color": false, // Button to change color of font
"blockquote": false, // Blockquote
   }});

     }, 1000);   

});



    });
于 2016-04-08T20:52:25.020 に答える
0

これを必要以上に複雑にしているように思えます。試してみてはどうですか:

$("#cleartext").click(function () {
    $('#def_text').val('');
});

このフィドルを参照してください。

于 2013-03-30T17:22:09.313 に答える
0

シングルページアプリケーションのデータをクリアするには、これを行う必要がありました。

私が試したとき

('#comments').data("wysihtml5").editor.clear() // Got error **Uncaught TypeError: Cannot read property 'editor' of undefined**

私が試したとき

var editor = $('#comments').wysihtml5();
editor.clear(); // This clears only the textarea which is hidden. Did not clear the Editor. 

これが私がやったことです(良いアプローチではないかもしれませんが、これでテキストエリアがクリアされました)

$(".wysihtml5-sandbox").remove();
$("#comments").show();
$('#comments').val('');

その後、エディタを再度初期化します。

var editor = new wysihtml5.Editor("comments", { // id of textarea element
  toolbar:      "wysihtml5-toolbar", // id of toolbar element
  parserRules:  wysihtml5ParserRules, // defined in parser rules set
  stylesheets: "/cca/css/richtext.css"
});
于 2015-01-15T23:26:41.193 に答える
0

これは私にとってはうまくいきました.数行のカスタムJSコードを書きます. 彼らはあなたを助けることができると思います。

var content = $('#textareaId');
var contentPar = content.parent()
contentPar.find('.wysihtml5-toolbar').remove()
contentPar.find('iframe').remove()
contentPar.find('input[name*="wysihtml5"]').remove()
content.show()
$('#textareaId').val('');
$("#textareaId").wysihtml5();
于 2016-07-28T05:51:30.627 に答える
0

私はブートストラップ 3 wysiHtml5 エディターを使用していますが、ここに記載されている解決策はどれもうまくいきませんでした。

$('#controlid ~ iframe').contents().find('.wysihtml5-editor').html('');

于 2019-03-19T13:03:19.287 に答える
-1

正しく初期化していますか?ドキュメントは次のようなものを示しています:

$(function () {
    var editor = new wysihtml5.Editor("def_text");

    $("#cleartext").on('click', function () {
        $('#def_text').data("wysihtml5").editor.clear();
    });
});

または、あなたの近くに、

var wysihtml5Editor = $('#def_text').wysihtml5();
于 2013-03-30T06:02:54.223 に答える