Php 引导-模式仅显示第一项
我正在使用Bootstrap来设计这个网页。此页面包含一个表格,我在其中使用Php 引导-模式仅显示第一项,php,twitter-bootstrap,loops,Php,Twitter Bootstrap,Loops,我正在使用Bootstrap来设计这个网页。此页面包含一个表格,我在其中使用modal显示有关所选项目的更多详细信息 我的问题是,表上的所有按钮只重定向到第一项的第一个细节。我想到了id名并将其放入数组中,但它不起作用(或者我做错了) 下面是一个示例代码,让您了解: <?php (loop){ $itemtopic=$loop['item']; $data=$loop['data']; ?> <button class="btn btn-primary" data-tog
modal
显示有关所选项目的更多详细信息
我的问题是,表上的所有按钮只重定向到第一项的第一个细节。我想到了id名并将其放入数组中,但它不起作用(或者我做错了)
下面是一个示例代码,让您了解:
<?php
(loop){
$itemtopic=$loop['item'];
$data=$loop['data'];
?>
<button class="btn btn-primary" data-toggle="modal" data-target="#myModal" style="float:right; margin-left:5px;" title="New User"><?php echo $itemtopic; ?></button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Create New User</h4>
</div>
<div class="modal-body">
<?php echo $data; ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php
} /* END OF LOOP */
?>
&时代;接近
创建新用户
接近
我如何显示所选项目的相应数据,而不仅仅是第一个项目的第一个细节?@Logon Wayne,关于您是否这样做有点模糊,因此您能否确认您是否正在打印带有X个模态的X个按钮,以及它们是否为每对都具有匹配的唯一ID 例如:
<?php
$rows = array('1'=>"afasdf",'2'=>"fagagadfg");
foreach($rows as $key=>$data):
?>
<button class="btn btn-primary" data-toggle="modal" data-target="#myModal<?php echo $key;?>" style="float:right; margin-left:5px;" title="New User">Create New User</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Create New User</h4>
</div>
<div class="modal-body">
<?php echo $data; ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php
endforeach;
?>
您不必循环模态元素,您需要的是在显示模态之前更改数据。请尝试以下代码:
<script>
//Please visit http://www.nokiflores.com
$(document).ready(
function() {
$("button.btn").click(
function(e) {
var parent_div = $(this).closes("div");
var val = $(parent_div).find("input[name=data]").val();
$("#modal_body").html(val );
$("#myModal").modal();
});
} );
});
</script>
<?php $_data = array(); $_data[] = array('id'=>1,'data'=>"data1", 'item'=>"item1"); $_data[] = array('id'=>2,'data'=>"data2", 'item'=>"item1"); ?>
<?php foreach($_data as $data ) { ?>
<div class="data">
<input type="hidden" value="<?php echo $data['data'] ; ?>" name="data" />
<!--please notice that i remove the modal functions in this button-->
<button class="btn btn-primary" id="<?php echo $data['id'] ; ?>" style="float:right; margin-left:5px;" title="New User"><?php echo $data['item'] ; ?></button>
</div>
<?php } ?>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Create New User</h4>
</div>
<div id="modal_body" class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
//请访问http://www.nokiflores.com
$(文件)。准备好了吗(
函数(){
$(“button.btn”)。单击(
职能(e){
var parent_div=$(此)。关闭(“div”);
var val=$(parent_div).find(“输入[名称=数据]”).val();
$(“#modal_body”).html(val);
$(“#myModal”).modal();
});
} );
});
&时代;接近
创建新用户
接近
很抱歉,但是您的回答(动态更改按钮的数据目标)
对我的问题没有帮助。我也在等待其他能很容易帮助我的答案。因为我认为这是一个简单的问题,只是我自己不知道如何解决它。@LogonWayne,你能分享你使用的不起作用的代码吗,因为你没有“动态”改变任何东西,你需要为每个单独的按钮打印一个单独的模式,并带有匹配的唯一ID->data target