提问人:Jayreis 提问时间:12/15/2022 最后编辑:Jayreis 更新时间:12/16/2022 访问量:198
将变量传递给 jquery 模态弹出窗口
Pass variable to jquery modal popup
问:
我有一个从 mysql 数据库中提取的 url 列表,需要将所选的特定 url 传递给 jQuery 模式窗口。
我的问题是我无法弄清楚如何传递数据并将其显示在jQuery模式中。下面是我的代码div
<table class="table responsive">
<thead><th>Topic</th><th></th></thead>
<tbody>
<tr>
<td>Phone System</td>
<td>
<button type="button" class="btn btn-default vidurl" data-videourl="https://foobar.s3.amazonaws.com/fake/url/vid.webm" data-toggle="modal" data-target="#modal-default">View Video</button>
</td>
</tr>
<tr>
<td>Ticket System</td>
<td>
<button type="button" class="btn btn-default vidurl" data-videourl="https://foobar.s3.amazonaws.com/fake/url/ticketvidinfo.webm" data-toggle="modal" data-target="#modal-default">View Video</button>
</td>
</tbody>
</table>
<div class="modal fade" id="modal-default">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Training Video</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<span class="viddata">what to show the video url here </span>
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<!-- below is my attempt to get the data from the button that was clicked and then set it as a variable and then make it load in a span inside the modal -->
<script>
$(document).ready(function(){
$(".vidurl").click(function(){
var vidurl = $('.vidurl').data(videourl);
$('.viddata').text(videourl);
console.log(videourl);
});
});
</script>
答:
0赞
cytek04
12/15/2022
#1
您没有完全正确地使用该属性。 是自定义属性。像 .然后,您可以在jQuery中访问,例如.data
Data
data-mycustomname
$(selector).data("mycustomname")
<button type="button" class="btn btn-default vidurl" data-url="https://foobar.s3.amazonaws.com/fake/url/vid.webm" data-toggle="modal" data-target="#modal-default">View Video</button>
然后在你的jQuery中
var vidurl = $('.vidurl').data("url");
评论