<div style="width: 600px; height: 500px;" class="modal-content"> <div class="modal-header"> <h5 class="modal-title">编辑</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <form> <div class="form-group"> <label for="detailInput">详情</label> <br> <textarea style="width: 570px; height: 300px;" class="form-control" id="detailInput" rows="5"></textarea> </div> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button> <button type="button" class="btn btn-primary">保存</button> </div> </div> 以上模态框中,我希望点击保存后,可以把 id= detailInput 中的内容用post请求发送给后端,后端我用的是flask。用jquery帮我实现
时间: 2023-04-04 19:01:20 浏览: 167
好的,我可以回答这个问题。您可以使用以下 jQuery 代码来实现:
```
$(document).ready(function() {
$('button.btn-primary').click(function() {
var detail = $('#detailInput').val();
$.post('/save', {'detail': detail}, function(response) {
// 处理响应
});
});
});
```
这段代码会在页面加载完成后,监听保存按钮的点击事件。当用户点击保存按钮时,它会获取 id 为 detailInput 的文本框中的内容,并将其作为 POST 请求的参数发送到后端的 /save 路由。您需要在 Flask 中编写一个视图函数来处理这个请求,并返回响应。
相关问题
.commodity-di .general, .draft_status { font-size: 14px; color: #e3ea07; margin-bottom: 10px; } .commodity-di .general { margin-bottom: 15px; } .commodity-di .pay_title { font-size: 14px; color: #10bdd8; border-radius: 10px; margin-top: -35px; margin-left: -1px; padding-bottom: 5px; } .commodity-di .pay_title span { background: linear-gradient(#15c6cf38, #0ab0e647); padding: 5px 30px 5px 30px; border-left: 1px dashed #15c8ca8f; border-top-left-radius: 10px; border-top-right-radius: 10px; border-bottom: none; } .commodity-di .pay-content { margin-top: 50px; border-left: 1px dashed #15c8ca8f; border-bottom: 1px dashed #15c8ca8f; border-right: 1px dashed #15c8ca8f; background: linear-gradient(#18cfc300, #97e2ef14); border-radius: 10px; border-top-left-radius: 0; } .commodity-di .pay_list { padding-left: 15px; padding-right: 15px; } 帮我用以上CSS做出一款渐渐显示的弹窗效果,并且要配合html
好的,下面是一个简单的渐显弹窗的样式和HTML代码:
HTML代码:
```
<div class="modal-wrapper">
<div class="modal">
<div class="modal-header">
<h3>提示</h3>
<button class="close-btn">×</button>
</div>
<div class="modal-body">
<p>这是一个渐显弹窗。</p>
</div>
<div class="modal-footer">
<button class="confirm-btn">确定</button>
<button class="cancel-btn">取消</button>
</div>
</div>
</div>
```
CSS代码:
```
/* 弹窗外层容器 */
.modal-wrapper {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.6);
z-index: 9999;
display: none;
}
/* 弹窗容器 */
.modal {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 400px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
opacity: 0;
}
/* 弹窗标题栏 */
.modal-header {
padding: 10px;
text-align: center;
background-color: #f5f5f5;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
/* 弹窗内容区域 */
.modal-body {
padding: 20px;
text-align: center;
}
/* 弹窗底部按钮区域 */
.modal-footer {
padding: 10px;
text-align: center;
background-color: #f5f5f5;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
/* 确认按钮样式 */
.confirm-btn {
background-color: #4caf50;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
margin-right: 10px;
}
/* 取消按钮样式 */
.cancel-btn {
background-color: #f44336;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
}
/* 关闭按钮样式 */
.close-btn {
position: absolute;
top: 0;
right: 0;
font-size: 30px;
color: #aaa;
background-color: transparent;
border: none;
padding: 0 10px;
outline: none;
}
/* 弹窗渐显动画 */
.modal.fade-in {
animation: fade-in 0.5s forwards;
}
@keyframes fade-in {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
```
JavaScript代码:
```
// 获取弹窗元素
var modalWrapper = document.querySelector('.modal-wrapper');
var modal = document.querySelector('.modal');
// 弹窗渐显函数
function fadeInModal() {
modal.classList.add('fade-in');
modalWrapper.style.display = 'block';
}
// 弹窗关闭函数
function closeModal() {
modal.classList.remove('fade-in');
modalWrapper.style.display = 'none';
}
// 确认按钮点击事件处理函数
function handleConfirmClick() {
console.log('点击了确认按钮');
closeModal();
}
// 取消按钮点击事件处理函数
function handleCancelClick() {
console.log('点击了取消按钮');
closeModal();
}
// 关闭按钮点击事件处理函数
function handleCloseClick() {
console.log('点击了关闭按钮');
closeModal();
}
// 绑定点击事件
document.querySelector('.confirm-btn').addEventListener('click', handleConfirmClick);
document.querySelector('.cancel-btn').addEventListener('click', handleCancelClick);
document.querySelector('.close-btn').addEventListener('click', handleCloseClick);
// 调用弹窗渐显函数
fadeInModal();
```
这是一个简单的渐显弹窗效果,你可以根据具体的需求进行自定义修改。
<button>登录</button> 添加登录失败弹出
当用户登录失败时,您可以通过弹出一个提示框来告诉用户登录失败的原因。以下是一个使用JavaScript和CSS实现的示例:
HTML代码:
```
<button id="login-btn">登录</button>
```
CSS代码:
```
.modal-mask {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
}
.modal-dialog {
background-color: #fff;
border-radius: 4px;
padding: 20px;
width: 300px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
position: relative;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.modal-header h3 {
margin: 0;
}
.close-btn {
border: none;
background-color: transparent;
font-size: 20px;
cursor: pointer;
}
.modal-body {
margin-top: 20px;
}
.modal-body input {
width: 100%;
margin-bottom: 10px;
padding: 8px;
border-radius: 4px;
border: 1px solid #ccc;
font-size: 14px;
}
.modal-footer {
display: flex;
justify-content: flex-end;
margin-top: 20px;
}
.modal-footer button {
border: none;
background-color: #007bff;
color: #fff;
padding: 8px 16px;
border-radius: 4px;
font-size: 14px;
cursor: pointer;
}
.modal-error {
color: red;
font-size: 14px;
margin-top: 10px;
}
```
JavaScript代码:
```
var loginBtn = document.getElementById("login-btn");
loginBtn.addEventListener("click", function() {
var loginModal = document.createElement("div");
loginModal.innerHTML = `
<div class="modal-mask"></div>
<div class="modal-dialog">
<div class="modal-header">
<h3>登录</h3>
<button class="close-btn">×</button>
</div>
<div class="modal-body">
<input type="text" placeholder="用户名">
<input type="password" placeholder="密码">
<div class="modal-error" style="display: none;">用户名或密码错误</div>
</div>
<div class="modal-footer">
<button class="login-btn">登录</button>
</div>
</div>
`;
loginModal.classList.add("modal");
document.body.appendChild(loginModal);
var closeBtn = loginModal.querySelector(".close-btn");
closeBtn.addEventListener("click", function() {
document.body.removeChild(loginModal);
});
var loginBtn = loginModal.querySelector(".login-btn");
loginBtn.addEventListener("click", function() {
var username = loginModal.querySelector("input[type='text']").value;
var password = loginModal.querySelector("input[type='password']").value;
if (username === "admin" && password === "123456") {
alert("登录成功");
document.body.removeChild(loginModal);
} else {
var errorDiv = loginModal.querySelector(".modal-error");
errorDiv.style.display = "block";
}
});
});
```
当用户输入的用户名或密码不正确时,提示框会显示"用户名或密码错误"的提示信息。您可以根据具体需求进行修改。
阅读全文
相关推荐
















