简体   繁体   English

javascript中的fadeIn(),fadeOut()不起作用

[英]fadeIn(),fadeOut() in javascript don't work

I want to use fadeIn and fadeOut in javascript in my webpage;but it doesn't work; 我想在网页的javascript中使用fadeIn和fadeOut;但是不起作用; it is my code;can you say me where is the problem?it doesn't fadeIn and fadeOut at all!!! 这是我的代码;您能告诉我问题出在哪里吗?它根本不淡入和淡出!!!

 $(document).ready(function () {

$("#DropDownList1").each(function () {

                $('ListItem', this).each(function () {

                    if ($(this).attr("selected") == true)

                        if (($(this).text() != "a")) {

                            $("div#select").fadeOut();
                                                  }
                        else {
                            $("div#select").fadeIn();

                        }
                });
            });
});

this is my dropdown list: 这是我的下拉列表:

 <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem Value=""></asp:ListItem>
            <asp:ListItem Value="m">a</asp:ListItem>
            <asp:ListItem Value="m1">b</asp:ListItem>
            </asp:DropDownList>

this is my actual html: 这是我实际的html:

<td class="style5" width="20%">
situation:&nbsp;
<br>
<select id="DropDownList1" name="DropDownList2">
<option value=""></option>
<option value="m">a</option>
<option value="m1">b</option>
</select>

Turning my comments into an answer... 将我的评论变成答案...

You should look at the actual HTML that the browser sees (not the ASP template code) because I don't think jQuery sees a ListItem in the HTML. 您应该查看浏览器看到的实际HTML(而不是ASP模板代码),因为我认为jQuery在HTML中看不到ListItem。 Standard dropdowns in HTML are <option> tags. HTML中的标准下拉列表是<option>标记。 Your ASP might be generating that or something else. 您的ASP可能正在生成该内容或其他内容。

Do a View/Source in the browser and look at the HTML that the browser actually sees and code your jQuery to that. 在浏览器中执行“查看/源代码”,查看浏览器实际看到的HTML,并为此编写jQuery。 $('ListItem', this) probably isn't finding anything. $('ListItem', this)可能找不到任何东西。 You should pretty much never go by the ASP code when writing jQuery to operate on it. 编写jQuery对其进行操作时,几乎应该永远不要使用ASP代码。 You need to know what the browser actually sees after the ASP template has been turned into regular HTML. 您需要知道将ASP模板转换为常规HTML后浏览器实际看到的内容。

FYI, a simplified version of your code that also runs any time the drop down list selection is changed works like this: 仅供参考,您的代码的简化版本在更改下拉列表选择时也可以运行,如下所示:

$(document).ready(function () {

    function checkDropDownList() {
        if ($("#DropDownList1 option:selected").text() != "a") {
           $("#select").fadeOut();
        } else {
            $("#select").fadeIn();
        }
    }

    checkDropDownList();

    $("#DropDownList1").change(checkDropDownList);

});

There's no reason to use .each() if there can only be one selected item and we already know there's only one DropDownList1 . 如果只有一个选定的项目,并且我们已经知道只有一个DropDownList1则没有理由使用.each()

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

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