如何获取data-id的值并将其放入Twitter Bootstrap模式? [英] How to get value of data-id and place it into a twitter bootstrap modal?
本文介绍了如何获取data-id的值并将其放入Twitter Bootstrap模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取数据库中包含和id的data-id的值.我需要获取admin_id并将其放入Twitter Bootstrap模式.我该如何使用Java脚本获得该值?
Im trying to get the value of the data-id which contains and id in my database. I need to get the admin_id and place it into a twitter bootstrap modal. How am I going to get that value using java script?
<a data-toggle="modal" data-id="<?=$row['ADMIN_ID'];?>" href="#view_contact" class="btn btn-info btn-xs view-admin">View</a>
这是我的模态
<div class="modal fade" id="view_contact" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4>Admin modal!!</h4>
</div>
<div class="modal-body">
Admin Id:<p id="showid"></p>
</div>
<div class="modal-footer">
<a class="btn btn-default" data-dismiss="modal">Close</a>
</div>
</div>
</div>
</div>
这是我的Java脚本
<script type="text/javascript">
$(document).on("click", ".view-admin", function () {
var adminid = $(this).data('id');
$(".modal-body #showid").val( adminid );
$('#view_contact').modal('show');
});
</script>
它没有显示在我的模态中.它们都在同一页面上.我该怎么做呢?有点新.
its not showing in my modal. They are all in the same page. How do I do this? Kinda new at this.
推荐答案
问题是,您正在尝试将值分配给p
标记. p
标记不具有value属性.使用text()
或html()
Problem is, you are trying to assign the value to a p
tag. p
tag does not have value property. Use text()
or html()
$(document).on("click", ".view-admin", function() {
var adminid = $(this).data('id');
$(".modal-body #showid").text(adminid);
$('#view_contact').modal('show');
});
这篇关于如何获取data-id的值并将其放入Twitter Bootstrap模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文