【问题标题】:Upload an image with wmd?用 wmd 上传图片?
【发布时间】:2010-09-27 09:13:05
【问题描述】:

是否可以使用 wmd 编辑器添加一个按钮,让用户将图像上传到 Web 服务器并将相应的 img markdown 放置在文本框中?如果没有,另一个好的就地编辑器会这样做吗?背景:我正在使用 asp.net mvc、C#,我是一个真正的 javascript 初学者。

【问题讨论】:

    标签: c# javascript asp.net-mvc file-upload wmd


    【解决方案1】:

    WMD 的简短阅读似乎表明此功能不受直接支持,并且该控件不是特别可插入的。

    话虽如此,没有什么能阻止您创建一个按钮/上传字段/任何将图像发送到您的服务器并注入适当的东西:

    <img src="http://your.server.com/path/to/attachments/..." />
    

    进入控件的底层文本区域。

    【讨论】:

      【解决方案2】:

      这是 WMD 附带的最小示例的变体:

          <!DOCTYPE html>
      <html>
        <head>
          <title>WMD minimal example</title>
          <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
          <script type="text/javascript">
          $.fn.insertAtCaret = function (myValue) {
                  return this.each(function(){
                          //IE support
                          if (document.selection) {
                                  this.focus();
                                  sel = document.selection.createRange();
                                  sel.text = myValue;
                                  this.focus();
                          }
                          //MOZILLA/NETSCAPE support
                          else if (this.selectionStart || this.selectionStart == '0') {
                                  var startPos = this.selectionStart;
                                  var endPos = this.selectionEnd;
                                  var scrollTop = this.scrollTop;
                                  this.value = this.value.substring(0, startPos)
                                                + myValue
                                        + this.value.substring(endPos,
          this.value.length);
                                  this.focus();
                                  this.selectionStart = startPos + myValue.length;
                                  this.selectionEnd = startPos + myValue.length;
                                  this.scrollTop = scrollTop;
                          } else {
                                  this.value += myValue;
                                  this.focus();
                          }
                  });
      
          };
      
          int i = 50;
      
          function Add()
          {
              $("#myTextarea").insertAtCaret("![alt text][" +(i++)+"]");
              // You'll need to add the link too, at the bottom
          }
          </script>
        </head>
        <body>
      
          <form>
          <a href="javascript:Add()">test</a>
              <textarea id="myTextarea" style="width: 500px; height: 200px;">*This* is a minimal example.</textarea>
          </form>
          <div class="wmd-preview"></div>
      
          <script type="text/javascript" src="wmd/wmd.js"></script>
        </body>
      </html>
      

      但这只是你可能知道的开始。 This markdown编辑器更好看

      【讨论】:

        【解决方案3】:

        我写了一个blog post,解释了我是如何解决这个问题的。在帖子中,我使用 PHP - 如果您愿意将我的 PHP 逻辑转换为 ASP.NET,您可能会发现它很有帮助!

        【讨论】:

          猜你喜欢
          • 2021-03-19
          • 1970-01-01
          • 2013-03-03
          • 2017-02-07
          • 2014-11-07
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多