gpt4 book ai didi

Jquery插入iframe的src属性作为它们各自的id

转载 作者:行者123 更新时间:2023-12-01 06:40:00 25 4
gpt4 key购买 nike

我正在尝试将 src 属性动态添加到 iframe,该属性取自它们各自的 id。

这是我正在处理的内容(使用了“this”的不当使用,但你应该明白我正在尝试做的事情。)

$(this).parent().find("iframe").attr('src', http://www.youtube.com/embed/" + $(this).attr('id'));

我的 iframe 代码如下所示:

<iframe id = "XpOPKZB8dgY" src=""></iframe>

更多背景信息(如果有帮助的话):

<script>    
$(document).ready(function() {
$("iframe").attr('src', '');
$(".details").slideUp();
$("a.date").click(function() {
var key = $(this).parent().attr('class');
$(this).parent().children("div").slideToggle('slow');
$(this).parent().find("iframe").attr('src', "http://www.youtube.com/embed/" + $(this).attr('id');
$(document.body).animate({
'scrollTop': $(this).offset().top
}, 1000);
});
});

</script>

谢谢!

最佳答案

你可以这样做:

$(this).parent().find("iframe").each(function(i) {
var src = 'http://www.youtube.com/embed/' + $(this).attr('id')
$(this).attr('src', src);
});

关于Jquery插入iframe的src属性作为它们各自的id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6061495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com