【问题标题】:Remove underline and blue color from link从链接中删除下划线和蓝色
【发布时间】:2013-01-04 04:26:20
【问题描述】:

我正在尝试禁用两个锚标记,但无法删除下划线。我也想去掉蓝色。这就是我所拥有的,它没有删除下划线。我已经尝试将 text-decoration 设置为 nonenone !important

        $(document).ready(function ()
        {
            // See if doc upload View and Remove panel is displayed --> do they currently have a document uploaded 
            var isInline = $("#ctl00_contentMain_pnlAuthorizationForReleaseViewUploadDocument").css('display');

            // if so disable upload and electronic sig links
            if (isInline == "inline")
            {
                //Disable Upload Link after document is uploaded
                $("#ctl00_contentMain_btnUpload").attr('onclick', '').click(function (e) {
                    e.preventDefault();
                });
                $("#ctl00_contentMain_btnUpload").attr('href', '');
                $("#ctl00_contentMain_btnUpload").attr('text-decoration', 'none !important');

                //Disable Electronic Sign Link after document is uploaded
                $("#ctl00_contentMain_lnkESign").attr('onclick', '').click(function (e) {
                    e.preventDefault();
                });
                $("#ctl00_contentMain_lnkESign").attr('href', '');
                $("#ctl00_contentMain_lnkESign").attr('text-decoration', 'none !important');
            }

        });

这里是aspx代码

<asp:LinkButton ID="lnkESign" 
                runat="server" 
                Text="sign"  
                TabIndex="1" 
                OnClick="lnkESign_Click">

<asp:LinkButton ID="lnkDownloadReleasefrm" runat="server" Text="Download"
                                        TabIndex="1"></asp:LinkButton>

Which renders this HTML

<a id="ctl00_contentMain_lnkESign" href="" tabindex="1" onclick="" text-decoration="none !important">sign</a>

<a href="" tabindex="2" id="ctl00_contentMain_btnUpload" onclick="" text-decoration="none !important">Upload </a>

编辑

这是我最终使用的代码

    $("#ctl00_contentMain_btnUpload").attr('href', '').css('text-decoration', 'none').css('color', 'black').attr('onclick', '').click(function (e) {
        e.preventDefault();
    });

【问题讨论】:

  • 良好实践说明:您应该考虑将对象 $("#ctl00_contentMain_lnkESign") $("#ctl00_contentMain_btnUpload") 存储在单个变量中,而不是总是向 DOM 请求它们。
  • fmsf 这样做有什么特别的原因吗?
  • 我写的一篇文章涵盖的是:franciscomsferreira.blogspot.com/2013/01/…

标签: jquery asp.net html


【解决方案1】:

text-decoration 不是属性.. 这是 css 中的规则。你应该像下面这样尝试,

$("#ctl00_contentMain_lnkESign").css('text-decoration', 'none');

注意:不需要!important,因为这将是一个内联样式。

【讨论】:

  • 它会做文字装饰吗:甚至悬停和点击事件都没有
  • 不,它不会使text-decoration:none 悬停。不确定onclick 事件是什么意思。
  • 通过 onclick 我的意思是,当我点击任何我给上面的 id 的锚标签时,当我点击那个锚标签时,'text-decoration' 不是没有。
【解决方案2】:

.css(key, value)代替.attr(key, value)

您将无法更改 :hover 、 :visited 等颜色,因为这些伪样式仅适用于样式表。将类添加到您的 css 文件中可能是有意义的,例如 .disabled,然后将该 css 类添加到带有 .addClass() 的链接中

【讨论】:

    【解决方案3】:

    您可能还需要考虑在样式表中为禁用的锚定义一个类,该类控制colortext-decoration,并使用 jquery 来切换该类而不是使用内联样式。

    CSS

    /* Applied to all anchors for default enabled appearance */
    .anchor
    {
      ...
    }
    
    /* Applied to display a disabled anchor */
    .anchor.disabled
    {
      color: #ddd;
      text-decoration: none;
    }
    

    JavaScript

    $("#ctl00_contentMain_lnkESign").toggleClass('disabled');
    

    【讨论】:

      猜你喜欢
      • 2011-02-16
      • 1970-01-01
      • 2015-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多