[英]Why in my JS popup my html form doesn't work?
我制作了一個彈出窗口,上面寫着“您確定要刪除該類別嗎?” 如果他們說是,執行一個表格但這個表格不起作用?
html代碼:
var modal = document.getElementById("popup"); var btns = Array.prototype.slice.call(document.querySelectorAll(".remove_openpopup")); var span = document.getElementsByClassName("close_button")[0]; btns.forEach(function(btn) { btn.onclick = function() { modal.style.display = "block"; } }); span.onclick = function() { modal.style.display = "none"; } span2.onclick = function() { modal.style.display = "none"; } window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } }
<body> <a href="#" class="remove_openpopup">remove</a> <a href="#" class="remove_openpopup">remove2</a> <a href="#" class="remove_openpopup">remove3</a> <div id="popup" class="popup"> <div class="popup_content"> <span class="close">×</span> <p>Are you sure you wan't delete this categorie ?</p> <button class="button_popup close_button">No</button> <button class="button_popup close_button" onclick='document.getElementByClassName("remove").submit()'>Yes</button> </div> </div> <form class="remove" method="post"><input type="hidden" name="remove" /></form> </body>
測試腳本:
if (isset($_POST['remove'])) {
echo "a";
}
當我單擊是時什么也沒有發生。 有人有想法嗎?
您正在使用 getElementByClassName 但它不存在。 最接近的是 getElementsByClassName,它返回具有所請求類名的元素數組,但在這種情況下,我認為您應該使用 getElementById 並將 id 屬性設置為您的表單:
<body>
<a href="#" class="remove_openpopup">remove</a>
<a href="#" class="remove_openpopup">remove2</a>
<a href="#" class="remove_openpopup">remove3</a>
<div id="popup" class="popup">
<div class="popup_content">
<span class="close">×</span>
<p>Are you sure you wan't delete this categorie ?</p>
<button class="button_popup close_button">No</button>
<button class="button_popup close_button" onclick='document.getElementById("remove").submit()'>Yes</button>
</div>
</div>
<form id="remove" method="post"><input type="hidden" name="remove" /></form>
</body>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.