jQuery fadeTo 效果应用于 ;

发布于 2024-08-02 17:59:41 字数 1329 浏览 5 评论 0 原文

我想使用 jQuery 将 fadeTo 效果添加到 标记。这应该是可以的吧?这是我的代码:

if ($) {
    $(document).ready(function() {
        $("tr[id$='_trPendingRequest_Manager']").fadeTo("slow", 0.33);
    });
}

无论出于何种原因,效果都没有发生。

我决定进行更多测试,并在包含此 的表格正上方添加了一个段落标记,并且我能够成功地将 fadeTo 效果应用到段落标签。因此,这让我认为不能将 fadeTo 效果应用于 标签。

任何有智慧的人都不介意与我分享为什么我不能让它发挥作用?

编辑:这是的html,其中>我正在尝试将效果应用到其中。

<table>
  <tr id="trPendingRequest_Manager" runat="server" style="display: none;" valign="middle">
    <td valign="middle">
      <asp:Image id="imgExc" runat="server" ImageUrl="~/Images/Mail_24x24.png" />
    </td>
    <td>&nbsp;</td>
    <td valign="middle">
      <asp:HyperLink ID="hypPendingRequest" runat="server" NavigateUrl="~/MyManagedRequests.aspx" Font-Bold="true" Font-Size="Medium" Font-Underline="false" ForeColor="Black">You have <asp:Label ID="lblRequestsNum" runat="server"></asp:Label>request(s) pending your action
       </asp:HyperLink>
    </td>
  </tr>
  <tr>... Removing the rest for brevity ... </tr>
</table>

I want to add the fadeTo effect to a <tr> tag using jQuery. This should be possible, right? Here's my code:

if ($) {
    $(document).ready(function() {
        $("tr[id$='_trPendingRequest_Manager']").fadeTo("slow", 0.33);
    });
}

For whatever reason, the effect is not happening.

I decided to do a bit more testing and added a paragraph tag directly above the table containing this <tr>, and I was able to successfully apply the fadeTo effect to the paragraph tag. So, this leads me to think that one cannot apply the fadeTo effect to <tr> tags.

Anyone have a nugget of wisdom they'd not mind sharing with me as to why I can't get this to work?

EDIT: Here's the html of the <table> with the <tr> which I am trying to apply the effect to.

<table>
  <tr id="trPendingRequest_Manager" runat="server" style="display: none;" valign="middle">
    <td valign="middle">
      <asp:Image id="imgExc" runat="server" ImageUrl="~/Images/Mail_24x24.png" />
    </td>
    <td> </td>
    <td valign="middle">
      <asp:HyperLink ID="hypPendingRequest" runat="server" NavigateUrl="~/MyManagedRequests.aspx" Font-Bold="true" Font-Size="Medium" Font-Underline="false" ForeColor="Black">You have <asp:Label ID="lblRequestsNum" runat="server"></asp:Label>request(s) pending your action
       </asp:HyperLink>
    </td>
  </tr>
  <tr>... Removing the rest for brevity ... </tr>
</table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寂寞美少年 2024-08-09 17:59:41

它工作得很好。如果这是唯一的 ID,那么您甚至不需要指定 tr 或匹配选择器,只需这样即可完成工作:

$(document).ready(){function(){
    $("#_trPendingRequestManager").fadeTo('slow','0.33');
});

编辑:-

因为我怀疑 id 来自 runat="server" 项。您可以使用它来加快速度。

$(document).ready(function(){
    $("#<%=trPendingRequestManager.ClientID %>").fadeTo('slow','0.33');
});

我认为开始 _ 让它表现得很有趣。有关使用 ClientID 属性加速的更多信息,请阅读 戴夫的这篇文章

还要删除“display:none”,这是罪魁祸首!

如果您不想删除 display:none,只需将其链接起来将不透明度设置为 0

$("#<%=trPendingRequestManager.ClientID %>")
 .css('opacity','0').show() //make transparent and show
 .fadeTo('slow','0.33')

我发现了这个 此处

It is working perfectly okay. If this is unique ID then you don't even need to specify tr or matching selector, simply this will do the work:

$(document).ready(){function(){
    $("#_trPendingRequestManager").fadeTo('slow','0.33');
});

EDIT:-

As I was suspecting the id comes from runat="server" item. You can use this to speed up things.

$(document).ready(function(){
    $("#<%=trPendingRequestManager.ClientID %>").fadeTo('slow','0.33');
});

I think starting _ was making it behave funny. For more on speeding up with using ClientID property read this post by Dave.

Also remove "display:none" this is the culprit!!!

just chain it to put opacity to 0 if you don't want to remove display:none

$("#<%=trPendingRequestManager.ClientID %>")
 .css('opacity','0').show() //make transparent and show
 .fadeTo('slow','0.33')

I found this here

柠北森屋 2024-08-09 17:59:41

一般来说,根据我的经验,tr 元素无法正常操作。例如,您可以向 tr 元素添加背景颜色(例如斑马条纹),但如果您希望每个 tr“行”之间有一条线,那么您必须将 css 边框添加到其下方的 td 元素,否则它不会好像有什么作用。

我的猜测是,这是类似的东西。您可能必须尝试在相关 tr 元素的每个子 td 元素上执行 fadeTo...不知道,我承认我没有测试任何内容。

Generally it's been my experience that tr elements can't be manipulated normally. For example, you can add a background color to tr elements (for zebra striping, say) but if you want a line between each tr "row" then you have to add the css border to the td elements under it or it won't seem to have any effect.

My guess is that this is something similar. You might have to try executing fadeTo on each child td element of the tr element in question... dunno, I admit I haven't tested anything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文