微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将“确认”弹出按钮标签“确定”和“取消”更改为“继续”和“返回页面”

如何解决将“确认”弹出按钮标签“确定”和“取消”更改为“继续”和“返回页面”

我需要将“确认”弹出按钮标签“确定”和“取消”更改为“继续”和“返回页面”。有人可以告诉我怎么做吗?我可以在用户点击 OK=true 和 Cancel=false 时进行处理;但我想将“确定”和“取消”标签更改为“继续”和“返回页面”。谢谢,莱拉

解决方法

首先,你是什么意思:

我有一个要求

我可以在用户点击 OK=true 和 Cancel=false 时进行处理

如果您想制作自定义对话框,您可以,但 JavaScript 中的 confirm() 函数不允许更改按钮内容。查看this tutorial with w3schools。它将帮助您实现目标(您所要做的就是自定义它并插入按钮)。这是他们的示例之一:

// Get the modal
var modal = document.getElementById("myModal");

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button,open the modal 
btn.onclick = function() {
  modal.style.display = "block";
}

// When the user clicks on <span> (x),close the modal
span.onclick = function() {
  modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal,close it
window.onclick = function(event) {
  if (event.target == modal) {
    modal.style.display = "none";
  }
}
body {font-family: Arial,Helvetica,sans-serif;}

/* The Modal (background) */
.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 1; /* Sit on top */
  padding-top: 100px; /* Location of the box */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgb(0,0); /* Fallback color */
  background-color: rgba(0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
  background-color: #fefefe;
  margin: auto;
  padding: 20px;
  border: 1px solid #888;
  width: 80%;
}

/* The Close Button */
.close {
  color: #aaaaaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
}

.close:hover,.close:focus {
  color: #000;
  text-decoration: none;
  cursor: pointer;
}
<h2>Modal Example</h2>

<!-- Trigger/Open The Modal -->
<button id="myBtn">Open Modal</button>

<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <span class="close">&times;</span>
    <p>Some text in the Modal..</p>
  </div>

</div>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。