【问题标题】:Create a Pop up window where user can choose name when saving file创建一个弹出窗口,用户可以在保存文件时选择名称
【发布时间】:2018-03-01 08:44:41
【问题描述】:

我有一个代码,用户可以在其中保存一个 txt 文件。在我使用 this.title + 'txt' 的函数中,但通过请求用户希望能够编写/选择文件的名称。 为此,我在想一个带有输入文本字段的弹出框,位于函数内部的某个位置,而无需更改现有的 html。这意味着我只想在调用函数时这样做。 能做到吗?

html页面中的按钮

    <button _ngcontent-c1="" class="btn btn-success">Spara insats och odds</button>

在download.service.ts中

    // Specifies JSON download
    downloadJSON() {
      this.download(this.title + '.txt', this.JSON, this.fileText)
    }

    // Specifies XML download
    downloadXML() {
      this.download(this.title + '.xml', this.XML,   this.xmlFile['body']);
    }

    // Creates downloadable link and triggers download
    download(filename, type, text) {
      var element = document.createElement('a');
      element.setAttribute('href', type + encodeURIComponent(text));
      element.setAttribute('download', filename);

      element.style.display = 'none';
      document.body.appendChild(element);

      element.click();

      document.body.removeChild(element);
    }

【问题讨论】:

    标签: javascript angularjs json popup


    【解决方案1】:

    Bootbox.js 可以帮助您。

    与:bootbox.prompt(message, callback)

    用一个简单的:

    bootbox.prompt("This is the default prompt!", function(result){ console.log(result); });
    

    您可以设置一个输入框供用户填写意图的文件名。

    Bootbox Prompt Examples

    【讨论】:

      猜你喜欢
      • 2022-01-13
      • 2016-04-12
      • 2013-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多