【发布时间】:2016-08-05 21:52:41
【问题描述】:
我有这个来自 Bootstrap 的 Modal 当我添加 按钮调用它打开成功, 但我真正需要的是从函数调用中自动打开这个模式 我的实验是:
<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">×</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'); 时,它会在页面加载时出现并再次出现在函数调用中,我怎样才能让它只出现在函数调用中
【问题讨论】:
-
什么时候给
AreYOuSureRenew打电话? -
来自另一个函数@RayonDabre 的 ajax 成功
-
调用函数AreYOuSureRenew();
-
@saraadly,请忽略我的评论,我浏览了您上面的第二条评论并很好地理解了您的情况。
-
控制台有错误吗?
标签: javascript jquery html twitter-bootstrap bootstrap-modal