简体   繁体   English

页面加载时不显示jQuery切换

[英]JQuery toggle doesn't show up when Page Loads up

I've UI issue to show "ShowLink". 我有UI问题显示“ ShowLink”。 It fades out when Page Loads up. 页面加载时淡出。 Logically it should fade out when user clicks ShowLink. 从逻辑上讲,当用户单击ShowLink时,它应该淡出。 Can anyone help me to fix the bug in the code ? 谁能帮助我修复代码中的错误?

<table width="100%">
    <tr>
        <td valign="top" style="padding-top: 20px;">
            <asp:Label ID="Label1" CssClass="number" runat="server" />
            <div>
                <a id="A1" href="#">Show Details</a>
            </div>
        </td>
        <td valign="top" style="padding-top: 20px;">
            <asp:Label ID="Label2" CssClass="question" runat="server" ClientIDMode="Static" />

            <div id="Div1">
            </div>
        </td>
    </tr>
</table>

<script type="text/javascript" src="/Scripts/jquery-1.7.2.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#showLink').toggle(function () {
            $('#questionDetails').load('/Reviews/Sub/ViewQuestion.aspx?id=<%= pageId %> #questionContainer');
            $('#questionDetails').fadeIn();
            $(this).text("Hide Detail...");
        },
    function () {
        $('#questionDetails').fadeOut();
        $(this).text("Show Detail...");
    }
    );
        var nmbr = $(".number");
        nmbr.parent().width(nmbr.width() + 50);
    });
</script>

Try to put the code inside the #showLink click event, 尝试将代码放入#showLink click事件中,

$('#showLink').click(function () {
        $('#questionDetails').load('/Reviews/Sub/ViewQuestion.aspx?id=<%= pageId %> #questionContainer');
        $('#questionDetails').fadeIn();
        $(this).text("Hide Detail...");
    },
function () {
    $('#questionDetails').fadeOut();
    $(this).text("Show Detail...");
}
);
    var nmbr = $(".number");
    nmbr.parent().width(nmbr.width() + 50);
});

I 've found a solution. 我找到了解决方案。 Issue is not with Code, Code is absolutely fine. 代码不是问题,代码绝对可以。 Issue is with JQuery Version that were used in the code is outdated and toggle doesn' t work currently with same version now. 问题在于代码中使用的JQuery版本已过时,并且切换功能目前不适用于同一版本。 Solution: We may resolve this issue following other way, I tried to avoid using toggle and worked find.Simply just add a if -else on click based upon id or text. 解决方案:我们可能会通过其他方式解决此问题,我试图避免使用切换和有效的find方法,只需在基于id或文本的点击上添加if -else。

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

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