sar*_*dly 7 javascript jquery html5 twitter-bootstrap bootstrap-modal
我有这个来自Bootstrap的Modal当我添加按钮时要调用它它已成功打开,但我真正需要的是从函数调用中自动打开这个模态我的实验是:
<button id="RenewCollerctorDateID" class="btn btn-success" style="width: 10%; display: inline;
padding-right: 10px; float: left;" onclick="RenewCollectorDatePeriod();">renew</button>
Run Code Online (Sandbox Code Playgroud)
我的JavaScript是
function RenewCollectorDatePeriod() {
// AreYOuSureRenew();
var EmpID = $("#<%=ddlFilterCollector.ClientID%>").val();
if (EmpID == -1) {
alert("please select one ")
}
else {
alert(EmpID);
GetCollectorInfo(EmpID);
}
}
Run Code Online (Sandbox Code Playgroud)
然后:
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');
}
Run Code Online (Sandbox Code Playgroud)
而这里是我的模态
<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>
Run Code Online (Sandbox Code Playgroud)
注意:当我$("#EnSureModal").modal('show');在Document.Ready中添加它在页面加载时出现并在函数调用中再次出现,我怎样才能使它出现在函数调用中
我读了你的代码,我发现你没有正确使用bootstrap,你写的脚本也不正确.看一下这个.这可能对你有帮助.
脚本:
$(document).ready(function(){
$("#fireme").click(function(){
$("#EnSureModal").modal();
});
});
Run Code Online (Sandbox Code Playgroud)
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">×</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>
Run Code Online (Sandbox Code Playgroud)
该小提琴
| 归档时间: |
|
| 查看次数: |
46109 次 |
| 最近记录: |