【问题标题】:Is there a way to disable a label?有没有办法禁用标签?
【发布时间】:2010-03-18 19:02:04
【问题描述】:

我正在使用 asp 单选按钮组在表单中列出答案。这是一个结构示例。

<asp:RadioButtonList id="Q2" runat="server">
    <asp:ListItem Text="Go to <a  target='_blank' href='http:www.google.com'>Google</a>"  Value="a"></asp:ListItem>
    <asp:ListItem Text="Go to <a  target='_blank' href='http:www.yahoo.com'>Yahoo</a>"  Value="a"></asp:ListItem>
 </asp:RadioButtonList>

所以我希望能够单击链接,而不是选择与之关联的单选按钮。在 IE 中它工作正常,但在 Firefox 中,当我单击链接时将选择单选按钮。我真的不需要标签来实际选择正确的单选按钮,所以有没有办法在 javascript 或 asp 或 C# 代码的某个地方禁用它们?

【问题讨论】:

  • 生成的 HTML 是什么样的?浏览器永远不会看到 ASP 代码。

标签: c# asp.net javascript


【解决方案1】:

毫无疑问,它将它们包装在 label 元素中,这为您提供了选择行为。你可以手动生成代码——我的选择——或者在客户端用javascript解包。

<div>
    <input type="radio" name="Q2" id="Q2_google" value="google" /> <a target="_blank" href="http://www.google.com">Google</a>
    ...
</div>

或客户端

 $(function() {
     $('label:has(a)').each( function() {
         var html = $(this).html();
         $(this).replaceWith($(html));
     });
 }); 

【讨论】:

  • 是的,jquery 看起来像是解决我注意到的大多数编码问题的方法。
【解决方案2】:

试试这个:

<a  target='_blank' href='http:www.google.com' click='return false;'>Google</a>"

【讨论】:

    【解决方案3】:

    您可以在 ListItem 级别使用 Enabled="false"

    例如: 谷歌"值="a"启用="假">

    【讨论】:

      猜你喜欢
      • 2021-10-18
      • 1970-01-01
      • 1970-01-01
      • 2018-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-28
      • 2014-11-22
      相关资源
      最近更新 更多