javascript - 提交多个输入值
问题描述
我将 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>
解决方案
我猜这个错误是由函数范围引起的。
尝试用insidevar
替换let
for (let i = 0)
推荐阅读
- c++ - 如何启动所有没有依赖关系的 TBB continue_nodes
- c - Cairo x11 不显示任何内容
- angular - 将 ngIf 与变量一起使用时仍包含 HTML
- java - Spring Data Projection 加载额外的字段
- c# - 带有 charset1252 的 ASP.NET Core Web API HttpPost
- c# - 如何从两个表中获取最大日期?
- apache-spark - spark可以忽略不可读的文件吗?
- ios - 在 ContactsUI ViewControllers 中忽略 CNContactBirthdayKey
- can-bus - 有没有办法在总线上接收之前修改 CANoe Rx 消息?
- json - 强制根 xml 元素成为 json 转换的数组