简体   繁体   English

如何在jQuery中使用此显示div

[英]how to show the div using this in jquery

what i need 我需要的

  • i just need to show div. 我只需要显示div。

code

<a href="javascript:void(0);" id="viewdetail" onclick="$(this).show();" style="color:green">view detail
    <div class="speakers dis-non">

    </div>
</a>
  • when I changed code to onclick="$('.speakers').show();" 当我将代码更改为onclick="$('.speakers').show();" then its working fine. 然后工作正常。

    problem occurs: 出现问题:

    • onclick="$(this).show()"

    • no div is shown. 没有显示div。

  • i need when user click on particular anchor element then data should of that particular link click should be shown. 我需要当用户单击特定锚元素时,则应显示该特定链接单击的数据。

You have to target element using: 您必须使用以下方式定位元素:

$(this).find('div').show();

Or to make it more specific with: 或更具体的说:

$(this).find('.speakers').show();

$(this) refers to the element you click on, in this case the a tag and not the div you want to show. $(this)指向您单击的元素,在这种情况下,是一个标签,而不是您要显示的div。

Try $(this).children('div').show(); 尝试$(this).children('div').show();

您必须使用以下命令选择第一个div元素:

$('this').children('div').show();

这将在锚标记中显示div

$(this).children(".speakers").show();

$(this) refers to the clicked anchor instead of the div. $(this)是指单击的锚点而不是div。 Use $(this).children('div.speakers').show(); 使用$(this).children('div.speakers').show(); to target div with speakers class inside the anchor. 将div与定位器内的speakers类一起定位。

<a href="javascript:void(0);" id="viewdetail" 
    onclick="$(this).children('div.speakers').show();" 
    style="color:green">view detail
    <div class="speakers dis-non">

    </div>
</a>

Working demo: http://jsfiddle.net/fw3sgc21/ 工作演示: http : //jsfiddle.net/fw3sgc21/

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

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