简体   繁体   English

jQuery查找功能不起作用

[英]jQuery find function doesn't work

I'm trying to do a pop-ip type thing using javascript and for some reason it doesn't work. 我正在尝试使用javascript做pop-ip类型的事情,由于某种原因它不起作用。 It shows no errors either. 它也没有显示错误。

<div style="cursor:pointer;" onclick="displayTickets('2013-12-27')" 
 onmouseover="displayMenu(this)" 
 onmouseout="hideMenu(this)" 
 bgcolor="#CCCCCC" width="14%" height="64" align="left" valign="top">
    27 Pre New Years Hotel Takeover
    <div class=".cPopUp" id="cPopUp5" style="position:absolute;z-index:1000;width:384px;height:192px;background-color:rgba(0,100,0,.8);left:0;top:0;right:0;padding:8px;text-allign:left;">
        <h4>Pre New Years Hotel Takeover</h4>
    </div>
</div>

.cPopUp is obviously the pop up I want to .show()/.hide() .cPopUp显然是我想要的弹出窗口.show()/。hide()

this is javascript: 这是javascript:

function displayMenu(el)
{
$(el).find(".cPopUp").show(500);

}

function hideMenu(el)
{
    $(el).find(".cPopUp").hide(500);
}

if I do 如果我做

 $(el).hide(500);

It hides the whole thing, so I know that works well, but I guess it's not finding anything? 它隐藏了整个事情,所以我知道这很好,但是我想它什么也没找到?

The class name is 类名是

class=".cPopUp"

ie it literally contains a period. 即,它实际上包含一个句点。 You would have to use .\\.cPopup as selector. 您将必须使用.\\.cPopup作为选择器。

But that's horrible, you should change the HTML to 但这太可怕了,您应该将HTML更改为

class="cPopUp"

instead. 代替。 This allows you to use the current selector ( .cPopup , the class ( . ) with name cPopup ). 这使您可以使用当前选择器( .cPopup ,名称为cPopup的类( . ))。

Your error is how you write the className in the HTML: 您的错误是如何在HTML中编写className:

<div class="cPopUp" id="cPopUp5" style="position:absolute;z-index:1000;width:384px;height:192px;background-color:rgba(0,100,0,.8);left:0;top:0;right:0;padding:8px;text-allign:left;">
    <h4>Pre New Years Hotel Takeover</h4>
</div>

There should not be a "." 不应有“。” when you write the className in the html, only when you declare it in the CSS 当您在html中编写className时,仅当您在CSS中声明它时

When setting a class for a tag never use the dot before the class name. 为标签设置类时,切勿在类名称前使用点。 Only uses dot when manipulating the selector. 仅在操作选择器时使用点。

<div class="cPopUp"></div>

Try it! 试试吧!

它应该是class="cPopUp"而不是class=".cPopUp"

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

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