将文本框值传递给cloudinary上传小部件?

时间:2019-10-31 19:21:41

标签: upload widget cloudinary

我需要设置图像标签并将上载小部件中的上载文件夹设置为文本框的值。我在js脚本中创建了一个全局变量,并在事件处理程序中为其分配了textbox.value。然后,将标记:[]和文件夹:(值)设置为全局变量。当我执行上传时,它不会获取变量的值。不过,奇怪的是,如果我对变量的值进行硬编码,则上载小部件确实会拾取该值并表现出预期的效果。同样奇怪的是,如果我使用console.log(全局变量),则会得到预期的输出,即textbox.value。

  <h1>This is the index page</h1>
</div>
<input type="text" id="campground">
<button id="upload_widget" class="cloudinary-button">Upload files</button>

<script type="text/javascript">
  var tagValue = "temper";
  var text = document.getElementById("campground");
  text.addEventListener("blur", function () {
    tagValue = text.value;
    console.log(tagValue);
  });

  var myWidget = cloudinary.createUploadWidget({
    cloudName: 'xxxx',
    apiKey: "xxxx",
    apiSecret: "xxxx",
    uploadPreset: 'xxxx',
    sources: ["local", "url", "camera", "dropbox", "facebook", "instagram"],
    showAdvancedOptions: true,
    tags: ["test", tagValue],
    folder: "campgrounds"
  }, (error, result) => {
    if (!error && result && result.event === "success") {
      console.log(tagValue + " not this time!");
      console.log('Done! Here is the image info: ', result.info);
    }
  }
  )
  document.getElementById("upload_widget").addEventListener("click", function () {
    console.log(tagValue + " not!");
    myWidget.open();
  }, false);```

0 个答案:

没有答案