简体   繁体   English

使用带有href标签的引导模态

[英]Use bootstrap modal with href tag

I have a table that looks like this 我有一张看起来像这样的桌子

Name  Occupation  Detail
abc   student     details

i want to set a bootstrap modal link on details column, which not only works as a model but also picks the id of that specific row. 我想在详细信息列上设置引导程序模式链接,该链接不仅可用作模型,还可以选择该特定行的ID。

At present i am working with this code 目前,我正在使用此代码

echo "<td><a href='#myModal'?id=".$row['id']."\" data-toggle='modal' data-target='#myModal '>Details</a></td>";

Modal is working properly but i am not able to use id of the row properly with the modal Would appreciate if someone could help me 模态工作正常,但我无法在模态下正确使用行的ID希望有人能帮助我

http://jsfiddle.net/0u19axax/1/ http://jsfiddle.net/0u19axax/1/

You can use show.bs.modal event to extract data from your a . 您可以使用show.bs.modal事件从a提取数据。

 $('#myModal').on('show.bs.modal', function(e){
     console.log($(e.relatedTarget).attr('data-id'))
 })

I moved the id to data-id because it did not work with the id in href 我将ID移至data-id因为它不适用于href的ID

<a href='#myModal' data-id='.$row['id'].' data-toggle='modal' data-target='#myModal '>Details</a>

Sorry, I don't know PHP so I'm not sure it'll work PHP wise. 抱歉,我不了解PHP,所以我不确定它是否可以在PHP上正常使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM