界面没有变化 ,实际上值已经改了,这样也不行。
$("#myButton").prop("value", "New Value");
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Button Value Update Example</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<button id="myButton">Click Me!</button>
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p>Some text in the Modal..</p>
<button id="confirmBtn">确认</button>
</div>
</div>
<script>
// 模态对话框的显示和隐藏
$(document).ready(function(){
$(".modal").css("display", "none");
$("#myButton").click(function(){
$(".modal").css("display", "block");
});
$(".close").click(function(){
$(".modal").css("display", "none");
});
$("#confirmBtn").click(function(){
$("#myButton").val("New Value");
$(".modal").css("display", "none");
});
});
</script>
<style>
/* 模态对话框的样式 */
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4);
}
.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
</style>
</body>
</html>