html禁用a標簽,html禁用選擇,html – 設置可選的禁用屬性

 2023-11-18 阅读 17 评论 0

摘要:似乎是自定義助手的一個很好的候選者:public static class HtmlExtensions{html禁用a標簽?public static IHtmlString TextBoxFor(this HtmlHelper htmlHelper,Expression> ex,object htmlAttributes,怎么打開網絡屬性、bool disabled){var attributes = new R

似乎是自定義助手的一個很好的候選者:

public static class HtmlExtensions

{

html禁用a標簽?public static IHtmlString TextBoxFor(

this HtmlHelper htmlHelper,

Expression> ex,

object htmlAttributes,

怎么打開網絡屬性、bool disabled

)

{

var attributes = new RouteValueDictionary(htmlAttributes);

HTML5 中不再支持下面哪個元素?()。if (disabled)

{

attributes["disabled"] = "disabled";

}

如何阻止ie和各大瀏覽器默認行為。return htmlHelper.TextBoxFor(ex, attributes);

}

}

可以像這樣使用:

表單元素禁用屬性,@Html.TextBoxFor(

m => m.PracticeName,

new { style = "width:100%" },

Model.PracticeName != String.Empty

css設置a標簽禁用、)

幫助器顯然可以更進一步,因此您不需要傳遞額外的布爾值,但它會自動確定表達式的值是否等于默認值(TProperty)并且它應用disabled屬性.

另一種可能性是這樣的擴展方法:

public static class AttributesExtensions

html自定義屬性。{

public static RouteValueDictionary DisabledIf(

this object htmlAttributes,

bool disabled

)

{

var attributes = new RouteValueDictionary(htmlAttributes);

if (disabled)

{

attributes["disabled"] = "disabled";

}

return attributes;

}

}

您將使用標準TextBoxFor幫助程序:

@Html.TextBoxFor(

m => m.PracticeName,

new { style = "width:100%" }.DisabledIf(Model.PracticeName != string.Empty)

)

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/178634.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息