我刚刚发现了 Sweet Alert,并希望以简单的形式确认来实现它,但我受到了信息的轰炸,并且我试图理解 JavaScript,但没有运气。
我想使用成功消息 here (第三个例子)但我不明白如何正确实现这一点。
我也希望之后刷新页面,但我需要先解决这个问题。
此外,是否可以使用 Sweet Alert 来验证表单中的空字段并显示错误消息?
我知道这一切都非常初级,我非常感谢您提供一些帮助,因为我对自己在做什么没有太多线索。
HTML
<form id="form" class="topBefore" action="<echo htmlspecialchars">
<div>
<h5 class="desc">Please Enter Your Information</h5>
<input type="text" placeholder="DONATION AMOUNT" />
<input type="text" placeholder="FIRST NAME">
<input type="text" placeholder="LAST NAME">
<input type="text" placeholder="ADDRESS" />
<input type="text" placeholder="CITY" />
<input type="text" placeholder="STATE" />
<input type="text" placeholder="ZIP" />
<input type="email" placeholder="E-MAIL">
<input type="text" placeholder="PHONE" />
<h5>How did you find Flower Spark / All Hallows Guild?</h5>
<input type="text" placeholder="How did you find Flower Spark?"/>
<div>
<h5>Select payment method:</h5>
<div class="pad-bot">
<select name="Field106" class="field select medium" tabindex="11">
<option value="First Choice">Credit Card/PayPal</option>
<option value="Second Choice">Check/Money Order</option>
</select>
</div>
</div>
<button id="submit">
<span class="state">Submit</span>
</button>
</div>
</form>
JS
swal("Good job!", "You clicked the button!", "success")
最佳答案
$('#form').on('submit', function () {
swal("Good job!", "You clicked the button!", "success")
});
或者
document.getElementById('submit').addEventListener('click', function () {
swal("Good job!", "You clicked the button!", "success")
});
关于javascript - 没有 JS 经验 - 如何使用 Sweet Alert 来确认表单提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43683741/