HTML
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>模态框传值 - 光年(Light Year Admin)后台管理系统模板</title>
<link rel="icon" href="favicon.ico" type="image/ico">
<meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
<meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
<meta name="author" content="yinqi">
<link href="http://lyear.itshubao.com/iframe/css/bootstrap.min.css" rel="stylesheet">
<link href="http://example.itshubao.com/demo/css/materialdesignicons.min.css" rel="stylesheet">
<link href="http://lyear.itshubao.com/iframe/css/style.min.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid p-t-15">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header"><h4>模态框的最大化</h4></div>
<div class="card-body">
<p>使用全局变量</p>
<button type="button" class="btn btn-primary btn-open" data-toggle="modal" data-target="#myModal">
打开模态框111
</button>
<button type="button" class="btn btn-primary btn-open" data-toggle="modal" data-target="#myModal">
打开模态框222
</button>
<button type="button" class="btn btn-primary btn-open" data-toggle="modal" data-target="#myModal">
打开模态框333
</button>
<p class="m-t-10">使用方法传参</p>
<button type="button" class="btn btn-primary btn-open2" data-toggle="modal" data-target="#myModal">
打开模态框444
</button>
<button type="button" class="btn btn-primary btn-open2" data-toggle="modal" data-target="#myModal">
打开模态框555
</button>
<button type="button" class="btn btn-primary btn-open2" data-toggle="modal" data-target="#myModal">
打开模态框666
</button>
<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">×</span></button>
<h4 class="modal-title" id="myModalLabel">标题</h4>
</div>
<div class="modal-body">
内容
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary btn-save">Save changes</button>
</div>
</div>
</div>
</div>
<pre class="m-t-10 shuchu"></pre>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="http://lyear.itshubao.com/iframe/js/jquery.min.js"></script>
<script type="text/javascript" src="http://lyear.itshubao.com/iframe/js/bootstrap.min.js"></script>
</body>
</html>
JavaScript
var thisObj;
$(document).ready(function() {
// 使用全局变量
$(document).on('click', '.btn-open', function() {
thisObj = this;
$(document).off('click', '.btn-save').on('click', '.btn-save', function() {
$('.shuchu').append('模态框上的按钮点击,当前是:');
$('.shuchu').append($(thisObj).html());
});
});
// 使用方法传参
$(document).on('click', '.btn-open2', function() {
caozuo(this);
});
});
// 方法
function caozuo(fangFaObj) {
$(document).off('click', '.btn-save').on('click', '.btn-save', function() {
$('.shuchu').append('模态框上的按钮点击,当前是:');
$('.shuchu').append($(fangFaObj).html());
// 模态框上的保存按钮点击事件,可在该方法内操作ajax提交保存数据
});
}