2

我有一个修改后的 pagedown markdown 标记脚本,用于将图像 url 插入编辑器,但它只在第一次工作。

我已经用注释解释了我的代码

 </script>
 <script type="text/javascript">
(function () {
 var converter = new Markdown.Converter();
 var help = function () { window.open('http://mywebsite.com/editing-help'); }
 var editor = new Markdown.Editor(converter);
 editor.hooks.set('insertImageDialog', function(callback) {
 setTimeout(function () 
{
        //i use bootstrap dialog to enter the url
        $('#fileModal').modal('show');  

        /*i have a button for clearing the textbox when i open 
        it the second time since when i open it the second 
        time the modal still contains what i had placed previously*/
        $("#clear").on("click", function(e) {
        e.preventDefault();
          $("#imgt").val(''); 
          $("#file").val('');
        });


        //the button that when clicked inserts the image url
        $("#insert_image_post").on("click", function(e) {
        e.preventDefault(); 

        //the image file being inserted
        if($("#imgt").val().length > 0)
        {
            var $url    =   $('input[type=text]');
            var image   =   $("#imgt").val();
            callback(image);
            $("#fileModal").modal('hide');

        }

    });


 }, 0);
return true; // tell the editor that we'll take care of getting the image url
 });

editor.run();

})();
</script>

任何使用 pagedown markdown javascript... 的想法来帮助我了解我哪里出错了?

4

1 回答 1

0

我设法让它工作

.on("click", function(e)...在我的情况下,它就像降价编辑器一样不能顺利运行。IE

$("#insert_image_post").on("click", function(e) {
e.preventDefault(); 

所以我在浏览了他们的文件后使用了他们的Markdown.Editor.js文件,即

var thebtn = document.getElementById("insert_image_post");
thebtn.onclick = function () {

下面的完整调整代码

<script>
(function () {
 var converter = new Markdown.Converter();
 var help = function () { window.open('http://stackoverflow.com/editing-help'); }
 var editor = new Markdown.Editor(converter);

 editor.hooks.set("insertImageDialog", function (callback) {

        $('#fileModal').modal('show');

            var thebtn = document.getElementById("insert_image_post");
            thebtn.onclick = function () {
                var images  =   $(".img-url").val();
                callback(images)
                 $('#fileModal').modal('hide');
            };

            var theclear = document.getElementById("clear");
            theclear.onclick = function () {

                  $("#imgt").val(''); 
                  $("#file").val('');

            };

    return true; // tell the editor that we'll take care of getting the image url
});

editor.run();

})();

</script>
于 2016-09-19T06:38:49.760 回答