【问题标题】:jquery toggle not working in chrome but working in IE and firefoxjquery toggle 在 chrome 中不起作用,但在 IE 和 firefox 中起作用
【发布时间】:2011-08-03 17:21:21
【问题描述】:

大家好 我有一个页面,我在一个跨度中显示文本,并且跨度控件在单击按钮时切换,基本上我为此使用 jquery。它在 IE 和 firefox 上运行良好,但在 chrome 上,当我点击关闭按钮(在跨度中切换它)时,它在我第一次点击它时不起作用,但在第一次点击后起作用。

请指教,代码如下

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="Assets/JS/jquery.js"></script>
    <script language="javascript">
        $.showmsg = function (msgEle, msgText, autoHide, isSuccess) {
            var tblMsg;
            var imgType;
            if (isSuccess) {
                imgType = "<img src='Assets/Images/icon_status_success_26x26.gif'/>"
            } else {
                imgType = "<img src='Assets/Images/icon_status_fail_26x26.gif'/>"
            }

            tblMsg = '<div id="container" style="width: 400px;"><b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b><div class="contain"><table width="100%" cellpadding="0" cellspacing="0" border="0" class=""><tr><td style="width:30px;" align="center" valign="middle">' + imgType + '</td><td>' + msgText + '</td><td style="width:30px;" align="center" valign="middle"><a href="javascript:void(0);"  onclick="$(\'#' + msgEle + '\').toggle(50);"><img src="Assets/Images/hide-icon.gif" border="0" alt="Hide" title="Hide"/></a></td></tr></table></div><b class="rbottom"><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b></div>';
            $("#" + msgEle).html(tblMsg);
            $("#" + msgEle).show();
            if (autoHide) {
                setTimeout(function () { $('#' + msgEle).fadeOut('normal') }, 10000);
            }
        }


        function Delete1() {
            $.showmsg('spnMessage', "Deleted", false, true);
        }

    </script>
    <style type="text/css">
        .rtop, .rbottom
        {
            display: block;
        }
        .rtop *, .rbottom *
        {
            display: block;
            height: 1px;
            overflow: hidden;
        }
        .r1
        {
            margin: 0 5px;
            background: yellow;
        }
        .r2
        {
            margin: 0 3px;
            background: yellow;
        }
        .r3
        {
            margin: 0 2px;
            background: yellow;
        }
        .r4
        {
            margin: 0 1px;
            height: 2px;
            background: yellow;
        }
        .contain
        {
            background: yellow;
            text-align: left;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <br />
    <br />
    <br />
    <table>
        <tr>
            <td>
                <asp:Button ID="btnDelete" runat="server" Text="Delete"  OnClientClick="Delete1(); return false;" />
            </td>
            <td>
                <span id="spnMessage" style="display: none;"></span>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

【问题讨论】:

    标签: javascript jquery asp.net css


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      我也有这个非常烦人的问题。我认为这与我们 HTML 中的一个怪癖有关,因为同一页面上的其他地方工作正常。

      我能够解决这个问题的唯一方法是:

      if($(#'element_id').css('display') == 'none'){
         $(#'element_id').show();
      }else{
         $(#'element_id').hide();
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-03
        • 1970-01-01
        • 2014-08-31
        相关资源
        最近更新 更多