[英]JavaScript Variable in Modal Window with Post or something else
i need a little help. 我需要一点帮助。 i have a javascript with the variable row_id.
我有一个带有变量row_id的JavaScript。 i need the variable in my bootstrap modal window.
我需要在我的引导模式窗口中的变量。 can anybody help me?
有谁能够帮助我?
<script type="text/javascript">
$("#myModal").modal();
$("tr button").click(function(e) {
e.preventDefault();
var row_id = $(this).closest("tr").attr("data-row-id");
alert(row_id);
});
</script>
here you see data-row-id. 在这里,您会看到data-row-id。
while($erg_motor = mysqli_fetch_assoc($db_erg_motor))
{
$body.='
<tr data-row-id='.$erg_motor['id'].'>
<td>'.$erg_motor['id'].'</td>
<td>'.$erg_motor['motor_name'].'</td>
<td>'.$erg_motor['motor_mail'].'</td>
<td>'.$erg_motor['motor_fabrikat'].'</td>
<td>'.$erg_motor['motor_modell'].'</td>
<td>'.$erg_motor['motor_ez'].'</td>
<td>'.$erg_motor['motor_km'].'</td>
<td>'.$erg_motor['motor_kraftstoff'].'</td>
<td>'.$erg_motor['motor_standort'].'</td>
<td>'.$erg_motor['motor_mailsperre'].'</td>
<td><button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Edit</button></td>
</tr>';
}
You need to append your variable on your modal body or title. 您需要在模态正文或标题上附加变量。
<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" aria-hidden="true">×</button>
<h4 class="modal-title" id="mtitle">Modal title</h4>
</div>
<div class="modal-body" id="mbody">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
Note the id mbody and mtitle. 注意id mbody和mtitle。 Here's how to append your variable
这是附加变量的方法
$('#mbody').html(yourvariable);
or 要么
$('#mtitle').html(yourvariable)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.