gpt4 book ai didi

javascript - 如何从函数调用 Jquery 打开模式

转载 作者:太空狗 更新时间:2023-10-29 14:14:14 27 4
gpt4 key购买 nike

我有这个来自 Bootstrap 的模态框当我添加按钮 调用它打开成功,但我真正需要的是从函数调用中自动打开这个模式我的实验是:

     <button id="RenewCollerctorDateID" class="btn btn-success" style="width: 10%; display: inline;
padding-right: 10px; float: left;" onclick="RenewCollectorDatePeriod();">renew</button>

我的 JavaScript 是

 function RenewCollectorDatePeriod() {
// AreYOuSureRenew();
var EmpID = $("#<%=ddlFilterCollector.ClientID%>").val();
if (EmpID == -1) {
alert("please select one ")
}
else {
alert(EmpID);
GetCollectorInfo(EmpID);
}
}

然后:

        function GetCollectorInfo(EmpID) {
// AreYOuSureRenew();
$.ajax({
type: "POST",
url: "UnloadingCalendar.aspx/GetCollectorInfo",
data: JSON.stringify({ EmpID: EmpID }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
alert(result.d);
AreYOuSureRenew();
},
error: function (msg) {
alert(msg.d);
},
complete: function () {

}
})
}


function AreYOuSureRenew() {
alert("opened");
$('#EnsureModal').modal('show');
}

这是我的模式

    <div class=" modal fade" id="EnSureModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Do ypu need change </h4>
</div>
<div class="modal-body">
<p>Are u sure from </p>
<label id="FromDate"></label>
<p>To</p>
<label id="ToDate"></label>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">no</button>
<button type="button" class="btn btn-default" data-dismiss="modal">yes</button>
</div>
</div>
</div>
</div>

注意:当我在 Document.Ready 中添加 $("#EnSureModal").modal('show'); 时,它会在页面加载时出现并在函数调用时再次出现,我该如何制作它只出现在函数调用中

最佳答案

我阅读了您的代码,发现您没有正确使用 bootstrap,而且您编写的脚本也不正确。看一下这个。这可能对您有所帮助。

脚本:

$(document).ready(function(){
$("#fireme").click(function(){
$("#EnSureModal").modal();
});
});

HTML:

<button id="fireme" class="btn btn-default">Fire me up!</button>
<div class="modal fade" id="EnSureModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Do ypu need change </h4>
</div>
<div class="modal-body">
<p>Are u sure from </p>
<label id="FromDate"></label>
<p>To</p>
<label id="ToDate"></label>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">no</button>
<button type="button" class="btn btn-default" data-dismiss="modal">yes</button>
</div>
</div>
</div>
</div>

fiddle

关于javascript - 如何从函数调用 Jquery 打开模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36621481/

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