Jquery - Using a function with .click and 'this'

Jquery - Using a function with .click and 'this'

本文关键字:and this click with Using function Jquery      更新时间:2023-09-26

糟糕的标题——对不起。

我正在使用embed,并且发现它有点难以理解。

我的目标是从API中提取标题和url,然后列出大约25个标题,并有一个按钮,按下时显示嵌入的url从embed.ly。

我目前的挣扎是,当我按下按钮显示嵌入的url,而不是它只显示我按下的1个链接,它决定一次显示所有25个链接。令人沮丧。

下面是我的代码:
$('#content').append('<div id="highlight"><h1 id="headline">
<a href="'+URL+'" base target="_blank">'+title+'</a></h1></br>
<img class="dropDown" src="images/drop-down.png" alt=""/>
<a class="embedly-card" href="'+URL+'"></a></div></br>');
$('.embedly-card').hide().removeClass('hide');

所以这工作得很好,embedly-card隐藏起来了,一切都很完美。我所纠结的部分是:

$(".dropDown").click(function() {
$(this).siblings('.embedly-card').toggle().toggleClass('toggle');
//This is the embedly code that creates the embeded features...
!function(a){var b="embedly-platform",c="script";if(!a.getElementById(b)){var d=a.createElement(c);d.id=b,d.src=("https:"===document.location.protocol?"https":"http")+"://cdn.embedly.com/widgets/platform.js";var e=document.getElementsByTagName(c)[0];e.parentNode.insertBefore(d,e)}}(document);
//End of embedly code...
$(this).toggleClass("on");

所以,正如我之前所说,而不是切换只是1个url,我打算它嵌入它嵌入所有25个url,当我点击dropDown,我在一个损失。我该如何解决这个问题?谢谢。

这应该能让你对问题有个大概的了解。

$('.dropDown').each(function(){
  // $(this) is each .dropDown
  // so it's like $(this).click(function(){});
}

你想对每个人都这样做。我没有看到足够的代码来总结其他内容,或者您的其余代码是否正确。