Javascript Pagedown标记脚本插入图像url一次
我有一个修改过的pagedown标记脚本,用于将图像url插入编辑器,但它只在第一次工作 我已经用注释解释了我的代码Javascript Pagedown标记脚本插入图像url一次,javascript,jquery,hook,markdown,pagedown,Javascript,Jquery,Hook,Markdown,Pagedown,我有一个修改过的pagedown标记脚本,用于将图像url插入编辑器,但它只在第一次工作 我已经用注释解释了我的代码 </script> <script type="text/javascript"> (function () { var converter = new Markdown.Converter(); var help = function () { window.open('http://mywebsite.com/editing-help'); }
</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>
(功能(){
var converter=新的Markdown.converter();
var help=function(){window.open('http://mywebsite.com/editing-help'); }
var编辑器=新的Markdown.editor(转换器);
editor.hooks.set('insertImageDialog',函数(回调){
setTimeout(函数()
{
//我使用引导对话框输入url
$('#fileModal').modal('show');
/*我有一个按钮,可以在打开时清除文本框
自从我第二次打开它以来,这已经是第二次了
时间模态仍然包含我之前放置的内容*/
$(“#清除”)。在(“单击”上,函数(e){
e、 预防默认值();
美元(“#imgt”).val(“”);
$(“#文件”).val(“”);
});
//单击时插入图像url的按钮
$(“#插入#图像#张贴”)。在(“单击”上,函数(e){
e、 预防默认值();
//正在插入的图像文件
如果($(“#imgt”).val().length>0)
{
var$url=$('input[type=text]');
var image=$(“#imgt”).val();
回调(图像);
$(“#fileModal”).modal('hide');
}
});
}, 0);
return true;//告诉编辑器我们将负责获取图像url
});
editor.run();
})();
任何一个有页面下降标记的javascript。。。帮助我了解哪里出了问题的想法?我设法让它起作用 在我的例子中,它就像markdown编辑器不能顺利运行
.on(“单击”,函数(e)…
$("#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>
(功能(){
var converter=新的Markdown.converter();
var help=function(){window.open('http://stackoverflow.com/editing-help'); }
var编辑器=新的Markdown.editor(转换器);
editor.hooks.set(“insertImageDialog”,函数(回调){
$('#fileModal').modal('show');
var thebtn=document.getElementById(“插入图片”post);
thebtn.onclick=函数(){
var images=$(“.img url”).val();
回调(图像)
$('#fileModal').modal('hide');
};
var theclear=document.getElementById(“清除”);
clear.onclick=函数(){
美元(“#imgt”).val(“”);
$(“#文件”).val(“”);
};
return true;//告诉编辑器我们将负责获取图像url
});
editor.run();
})();