Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 views
in Technique[技术] by (71.8m points)

javascript - 使用模式窗口作为一般消息或删除确认(Using a modal window as a generic message or delete confirmation)

I'm trying to piece together some code, whichI can use as a universal modal popup message, or prompt to confirm a delete.

(我正在尝试整理一些代码,可以将其用作通用模式弹出消息,或提示您确认删除。)

Therefore, if it's just a message, it only needs a close or ok button, but if it's a delete confirmation, then it needs an ok, which then lets the script follow the link which was clicked (as it can hold all the IDs from the records), and if cancel is clicked, it returns false.

(因此,如果仅是一条消息,则只需要一个关闭或“确定”按钮,但是如果它是一个删除确认,则它需要一个“确定”,然后让脚本跟随单击的链接(因为它可以保存来自记录),如果单击“取消”,则返回false。)

However, at the moment, the window pops up, I can see button with the innerhtml being populated, but it follows the link straight away.

(但是,此刻窗口随即弹出,我可以看到其中填充了innerhtml的按钮,但它会立即跟随链接。)

Any help would be wonderful!

(任何帮助都将是美好的!)

Many thanks

(非常感谢)

 <script> function msgModal(alerttype){ if (alerttype=="del"){ document.getElementById("cancelbtn").innerHTML = "<a href=''>Cancel</a>"; document.getElementById("confirmbtn").innerHTML = "<a href='test.php?ID="+id+"'>Delete Me</a>"; document.getElementById("modalmsg").innerHTML = "<p>Are you sure you want to delete this item?</p>" }else if (alerttype=="msg"){ document.getElementById("cancelbtn").innerHTML = "<button type=\"button\">Ok</button>"; document.getElementById("confirmbtn").innerHTML = ""; document.getElementById("modalmsg").innerHTML = "<p>This is a message</p>" } var modal = document.getElementById("myModal"); // Get the <span> element that closes the modal var span = document.getElementsByClassName("close")[0]; var cancel = document.getElementsByClassName("cancel")[0]; // When the user clicks the button, open the modal modal.style.display = "block"; // When the user clicks on <span> (x), close the modal span.onclick = function() { modal.style.display = "none"; } cancel.onclick = function() { modal.style.display = "none"; return false; } // When the user clicks anywhere outside of the modal, close it window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } } </script> <link rel="stylesheet" href="message/message.css"> <!--Then this code shows the links to trigger the functions_ <!-- Trigger/Open The Modal --> <p><a href="test.php?id=1" onclick="return msgModal('del');">Delete Option</a> | <a href="test.php?id=2" onclick="return msgModal('msg');">Message Option</a> </p> <!-- This is the model window which pops up to confirm the message or delete --> <div id="myModal" class="modal"> <!-- Modal content --> <div class="modal-content"> <span class="close">&times;</span> <div id="modalmsg"></div> <div id="modalbtns"> <span class="cancel" id="cancelbtn"></span> <span id="confirmbtn"></span> </div> </div> </div> 

  ask by petworthnick translate from so


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...