Asp.net mvc 3 仅当启用javascript时隐藏标签元素 我有一个显示文本框的视图,如下所示:

Asp.net mvc 3 仅当启用javascript时隐藏标签元素 我有一个显示文本框的视图,如下所示:,asp.net-mvc-3,Asp.net Mvc 3,我在上面的代码中使用,但没有隐藏标签。我能做什么?当您使用@Html.label(“CodeGuest”)时,它将呈现下面的Html <label for="CodeGuest">CodeGuest</label> 我建议您使用另一种Html.Labelhelper方法,您可以在其中指定Html属性,从而为标签定义ID元素 @Html.Label("CodeGuest", new { @id="codeGuest"}) 这将为您提供带有ID元素的标记,以便您可以使用

我在上面的代码中使用,但没有隐藏标签。我能做什么?

当您使用
@Html.label(“CodeGuest”)
时,它将呈现下面的Html

<label for="CodeGuest">CodeGuest</label>
我建议您使用另一种
Html.Label
helper方法,您可以在其中指定Html属性,从而为标签定义
ID
元素

 @Html.Label("CodeGuest", new { @id="codeGuest"})
这将为您提供带有
ID
元素的标记,以便您可以使用该标记隐藏元素

<label id="codeGuest" for="CodeGuest">CodeGuest</label>
始终尝试使用特定的jQuery选择器(ID而不是类名等),而不是通用的。那更快

$(function() {
    $('label[for="CodeGuest"]').hide();
});
 @Html.Label("CodeGuest", new { @id="codeGuest"})
<label id="codeGuest" for="CodeGuest">CodeGuest</label>
$(function() {
    $("#codeGuest").hide();
});