作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
实际上我有两个 ID 为 myModal1、myModal 的模态,它们包含不同的表。当用户输入一些值时,#myModal 将打开并显示其在 MODALBODY 中的表。当用户未输入某些值时,#myModal1 将显示为另一个有自己的 MODALBODY 的表。当用户输入或不输入值时,我需要显示同一张表。
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="global.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<style type="text/css">
.table {
border-radius: 5px;
width: 100%;
margin: 0px auto;
float: none;
}
</style>
</head>
<body>
<form class="form-inline" action="">
<div class="form-group">
<label for="test" class="col-sm-3 control-label">ClientId</label>
<input type="text" class="form-control" id="test" placeholder="Enter A Value">
</div>
<div class="form-group">
<button type="button" id="go" class="btn btn-primary"> <span class="glyphicon glyphicon-search"></span></button>
</div>
</form>
<!--Modal if input is empty-->
<div class="modal fade" id="#myModal">
<div class="modal-dialog">
<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">Modal title</h4>
</div>
<div class="modal-body">
<!--div class="container"-->
<h2>Basic Table</h2>
<div class="table-responsive">
<table id="relativeTable" class="table table-hover table-striped table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>CID</th>
</tr>
</thead>
<tbody>
<tr>
<td>JohnALIBABBABABABA</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
<!--/div-->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!--modal if there is some text-->
<!--Modal-->
<div class="modal fade" id="#myModal1">
<div class="modal-dialog">
<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>
<h3 class="modal-title modal-title-or">
Edit
Relative
</h3>
</div>
<form id="relativeFormEdit" class="form-horizontal">
<div class="modal-body">
<!--form body-->
<div class="form-group ">
<div class="row">
<label class="control-label col-md-4">Name:</label>
<div class="col-md-6">
<input name="name" title="Name" class="form-control">
</div>
</div>
<div class="row">
<label class="control-label col-md-4">Age:</label>
<div class="col-md-6">
<input name="age" title="age" class="form-control">
</div>
</div>
<div class="row">
<label class="control-label col-md-4">Cid:</label>
<div class="col-md-6">
<input name="cid" title="cid" class="form-control">
</div>
</div>
<div class="col-md-10">
<button type="button" class="btn btn-info btn pull-right" id="search" >
<span class="glyphicon glyphicon-search"></span>Search
</button>
</div>
<div>
<table class="table" id="table1">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>CID</th>
</tr>
</thead>
<tbody>
<tr>
<td>JohnAAAAA</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
</form>
<script>
$(document).ready(function(){
$('#go').click(function() {
var test1 = $('#test').val();
if (test1 === "") {
$('#\\#myModal1').modal('show');
$('#table1').hide();
}
else{
$('#\\#myModal').modal('show');
}
$('#search').click(function() {
$("#table1").show();
});
});
});
</script>
<!-- /.modal -->
<!--End Modal-->
</body>
</html>
最佳答案
据我了解,您需要在 table1 模式框中显示 #relativeTable 表,因此您需要使用 $( ".table-responsive").clone().appendTo( "#appendDiv");
并克隆那个特定的表并在你需要的地方显示我在我显示克隆表的地方添加了#appendDiv id
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="global.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<style type="text/css">
.table {
border-radius: 5px;
width: 100%;
margin: 0px auto;
float: none;
}
</style>
</head>
<body>
<form class="form-inline" action="">
<div class="form-group">
<label for="test" class="col-sm-3 control-label">ClientId</label>
<input type="text" class="form-control" id="test" placeholder="Enter A Value">
</div>
<div class="form-group">
<button type="button" id="go" class="btn btn-primary"> <span class="glyphicon glyphicon-search"></span></button>
</div>
</form>
<!--Modal if input is empty-->
<div class="modal fade" id="#myModal">
<div class="modal-dialog">
<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">Modal title</h4>
</div>
<div class="modal-body">
<!--div class="container"-->
<h2>Basic Table</h2>
<div class="table-responsive">
<table id="relativeTable" class="table table-hover table-striped table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>CID</th>
</tr>
</thead>
<tbody>
<tr>
<td>JohnALIBABBABABABA</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
<!--/div-->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!--modal if there is some text-->
<!--Modal-->
<div class="modal fade" id="#myModal1">
<div class="modal-dialog">
<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>
<h3 class="modal-title modal-title-or">
Edit
Relative
</h3>
</div>
<form id="relativeFormEdit" class="form-horizontal">
<div class="modal-body">
<!--form body-->
<div class="form-group ">
<div class="row">
<label class="control-label col-md-4">Name:</label>
<div class="col-md-6">
<input name="name" title="Name" class="form-control">
</div>
</div>
<div class="row">
<label class="control-label col-md-4">Age:</label>
<div class="col-md-6">
<input name="age" title="age" class="form-control">
</div>
</div>
<div class="row">
<label class="control-label col-md-4">Cid:</label>
<div class="col-md-6">
<input name="cid" title="cid" class="form-control">
</div>
</div>
<div class="col-md-10">
<button type="button" class="btn btn-info btn pull-right" id="search" >
<span class="glyphicon glyphicon-search"></span>Search
</button>
</div>
<div id="appendDiv"></div>
<div>
<table class="table" id="table1">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>CID</th>
</tr>
</thead>
<tbody>
<tr>
<td>JohnAAAAA</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
</form>
<script>
$(document).ready(function(){
$('#go').click(function() {
var test1 = $('#test').val();
if (test1 === "") {
$('#\\#myModal1').modal('show');
$('#table1').hide();
$( ".table-responsive" ).clone().appendTo( "#appendDiv" );
}
else{
$('#\\#myModal').modal('show');
$("#table1").show();
}
});
$("#search").click(function(){
$("#table1").show();
})
});
</script>
<!-- /.modal -->
<!--End Modal-->
</body>
</html>
关于javascript - 在两个不同的 MODAL BODY Bootstrap 中加载同一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49532563/
我正在开发一个需要能够平均三个数字的 Facebook 应用程序。但是,它总是返回 0 作为答案。这是我的代码: $y = 100; $n = 250; $m = 300; $number = ($y
我只是无法弄清楚这一点,也找不到任何对我来说有意义的类似问题。我的问题:我从数据库中提取记录,并在我的网页上以每个面板 12 条的倍数显示它们。因此,我需要知道有多少个面板可以使用 JavaScrip
我是一名优秀的程序员,十分优秀!