首页 > 解决方案 > 提交多个输入值

问题描述

我将 Sweetalert Popup 中的值传递给表单,然后我收到每封电子邮件发送给我的输入。由于我有多种选择让用户提供他的输入,因此只有最后一个输入被提交。在这种情况下,创建一个 Javascript 数组并将其作为 JSON 提交会帮助我吗?

// TextArea

var TextAreas = document.getElementsByClassName('bemerkung')
// go through all elements with the same ClassName
for (var i = 0; i < TextAreas.length; i++) {
  var TextArea = TextAreas[i]
  TextArea.addEventListener('click', function() {
    Swal.fire({
      title: '<strong>Bemerkung</strong>',
      input: 'textarea',
      inputPlaceholder: "Wir geben unser Bestes den Wunsh zu erfüllen"
    }).then(result => {
      var string = result.value;

      // target iframe inside index.php
      var iframe = document.getElementById('checkout')
      // get iframe content
      var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
      // Creating a new hidden input node in that target form;  
      var bemerkung = innerDoc.getElementById('f36')
      bemerkung.value = string
    });
  })
}
.bemerkung {
  position: relative;
  left: 30px;
  top: 0px;
  width: 25px;
  height: 25px;
  background-color: transparent;
  background-image: url(https://uploads-ssl.webflow.com/5df78d3035688c75f8199fe6/5f3830b87c03d7ae736cc485_pen%20loading-editing.svg);
  background-position: 0 50%;
  background-size: auto;
  background-repeat: no-repeat;
  background-attachment: scroll;
  color: transparent;
  outline: none;
  border: none;
}
<button class="bemerkung w-button" type="button"></button>
<br>
<button class="bemerkung w-button" type="button"></button>
<br>
<button class="bemerkung w-button" type="button"></button>
<br>
<button class="bemerkung w-button" type="button"></button>


<iframe src="Checkout/form.html" scrolling="yes" id="checkout" style="min-width:280px;width:100%;height:600px;border:none;" frameborder="none" allowTransparency="true">
</iframe>




<!-- Modal Popup-->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9" defer></script>

标签: javascript

解决方案


我猜这个错误是由函数范围引起的。
尝试用insidevar替换letfor (let i = 0)


推荐阅读