gpt4 book ai didi

jquery - 单击按钮时不显示模态

转载 作者:行者123 更新时间:2023-12-01 06:10:00 25 4
gpt4 key购买 nike

我需要帮助来使用 ajax 显示模式。我已经有了代码,但是单击按钮时,模式不显示。显示了淡入淡出,但没有出现模态。

这是我的按钮和模式

<button class="btnView" data-target="#myModal" role="button">View Details</button>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
</div>
</div>
</div>

在下面,我有一个脚本,它将获取 view_modal.php 中的内容并将其放入 modal-content 类中。

$(".btnView").click(function(){
if(ID!=""){
$.ajax
({
type: "POST",
url: "view_modal.php",
cache: false,
success: function(html)
{
$(".modal-content").html(html);
}
});
}else{
$('.modal-content').html("<div class='modal-header'><button type='button' class='close' id='btnClosemodal' data-dismiss='modal' aria-hidden='true'>&times;</button><h4 class='modal-title' id='myModalLabel'>Select Record</h4></div><br/><center>Please select a record first before clicking view button.</center><br/>");
}
$('.modal').modal('show');
});

这是view_modal.php

<div class="modal-header">
<button type="button" id="btnClosemodal" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">View Details</h4>
</div>

<div class="modal-body">
<div id="form1" method="post">
<div class="modal-body">
<p>Title:</p>
<p>Message:</p>
</div>
<div class="modal-footer">
<button id="btnClosemodal" data-dismiss="modal" class="btn btn-danger">CLOSE</button>
</div>
</div>
</div>

最佳答案

这是按钮,

<button id="btnAdd" data-toggle="modal" data-target="#myModal" class="btn-group-sm btn-primary" value="Search"><span class="glyphicon glyphicon-plus">Add New</span></button>

这是显示模态框的 html,

 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
Name: <input type="text" id="txtName" name="name" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" id="submit" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>

关于jquery - 单击按钮时不显示模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41205487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com