跨浏览器Javascript XML解析[关闭](Cross-Browser Javascript XML Parsing)
有没有跨浏览器/跨平台的方式来解析Javascript中的XML文件?
Are there any cross-browser / cross-platform ways to parse XML files in Javascript?
原文:https://stackoverflow.com/questions/7949752
最满意答案
大约一个月前我有同样的问题,我完成了使用这种扩展方法
public static class AttributesExtensions { public static RouteValueDictionary DisabledIf( this object htmlAttributes, bool disabled ) { var attributes = new RouteValueDictionary(htmlAttributes); if (disabled) { attributes["disabled"] = "disabled"; } return attributes; } }
之后你可以像这样使用它
@Html.TextBoxFor( model => model.Street, new { @class = "" }.DisabledIf(Model.StageID==(int)MyEnum.Sth) )
data-xxx
html属性的使用可以通过使用System.Web.Routing.RouteValueDictionary类的构造函数来挖掘,因为下划线不会自动转换为减号。改为使用方法System.Web.Mvc.HtmlHelper.AnonymousObjectToHtmlAttributes :将解决此问题。
更新代码 (仅限扩展方法主体)
var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); if (disabled) { attributes["disabled"] = "disabled"; } return attributes;
I have the same problem about month ago and I finished by using this extension method for it
public static class AttributesExtensions { public static RouteValueDictionary DisabledIf( this object htmlAttributes, bool disabled ) { var attributes = new RouteValueDictionary(htmlAttributes); if (disabled) { attributes["disabled"] = "disabled"; } return attributes; } }
And after that you can use it like this
@Html.TextBoxFor( model => model.Street, new { @class = "" }.DisabledIf(Model.StageID==(int)MyEnum.Sth) )
The using of
data-xxx
html attributes may be mined by using the constructor of the System.Web.Routing.RouteValueDictionary class, since underscores will not be automatically converted to minus sign.Use the method System.Web.Mvc.HtmlHelper.AnonymousObjectToHtmlAttributes instead: will solve this issue.
UPDATED CODE (Extension method body only)
var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); if (disabled) { attributes["disabled"] = "disabled"; } return attributes;
相关问答
更多-
TextBoxFor呈现为带有ID属性前缀的HTML(TextBoxFor rendering to HTML with prefix on the ID attribute)[2022-06-18]
看来MVC 2 RTM目前不提供此功能。 你可以尝试这些扩展方法: public static MvcHtmlString ValidationMessageFor(this HtmlHelper htmlHelper, string prefix, Expression > expression) { return ValidationMessageF ... -
为TextBoxFor HtmlHelper动态设置禁用的html属性(Dynamically set the disabled html attribute for TextBoxFor HtmlHelper)[2023-04-02]
大约一个月前我有同样的问题,我完成了使用这种扩展方法 public static class AttributesExtensions { public static RouteValueDictionary DisabledIf( this object htmlAttributes, bool disabled ) { var attributes = new RouteValueDictionary(htmlAttributes ... -
根据Html.TextBoxFor的条件设置disable属性(Set disable attribute based on a condition for Html.TextBoxFor)[2022-10-30]
有效的方法是: disabled="disabled" 浏览器也可能会接受 disabled=""但我会推荐你第一种方法。 现在这是说我建议你编写一个自定义的HTML帮助器,以将这个禁用功能封装成可重用的代码片段: using System; using System.Linq.Expressions; using System.Web; using System.Web.Mvc; using System.Web.Mvc.Html; using System.Web.Routing; public s ... -
仅来自TextBoxFor()的日期(Date only from TextBoxFor())[2021-07-18]
[DisplayName("Start Date")] [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")] public DateTime StartDate { get; set; } 然后: <%=Html.EditorFor(m => m.StartDate) %> [DisplayName("Start Date")] [DisplayFormat(ApplyFormatInEdit ... -
我相信在设置新值之前,您必须在[HttpPost]操作中调用ModelState.Clear() 。 根据这个答案,其中有一个非常好的解释: 如何更新文本框的值@ Html.TextBoxFor(m => m.MvcGridModel.Rows [j] .Id) 另请参阅: ASP.NET MVC 3 Ajax.BeginForm和Html.TextBoxFor不反映在服务器上完成的更改尽管看起来您没有使用Ajax.BeginForm ,但其行为相同。 包括@Scheien建议的示例: [HttpPost] ...
-
禁用HTML.TextBoxFor()(disabling HTML.TextBoxFor())[2022-11-16]
这是设计。 禁用的输入不会回发到服务器。 您可以使用'readonly'使输入为'只读'。 这将使数据被POSTED,但用户不能以传统方式编辑信息。 请记住,人们可以使用像Firebug或Dragonfly这样的工具编辑数据并将其发回。 因此,坚持脚趾,并确保数据是相同的,或者更好,只需使用disabled属性即可。 This is by design. Disa ... -
你可以这样做来添加一个名为singleTextBox的CSS类,然后你可以在样式表中分配一个宽度: <%= Html.TextBoxFor(model => model.UserName, new { @class = "singleTextBox" }) %> 在你的样式表中: .singleTextBox { width: 12em; } You can do this to add a CSS class called singleTextBox, and then you can ass ...
-
如果您尝试在用户键入时设置文本框的宽度,则可以使用jQuery来完成此操作。 但是你还不清楚决定文本框长度的因素,所以如果你想让文本框的大小随着用户类型的增加而增加,你可以使用这样的东西: $('#abc').on('keyup', (function() { var size = $(this).val().length(); $(this).css( 'width', size + 'px' ); }); If you are trying to set the width of the t ...
-
Html.TextBoxFor设置值(Html.TextBoxFor set value)[2023-09-19]
你需要使用javascript来实现这一目标。 这是jquery的一个例子: $(function() { $('#fileId').change(function() { // When the user selects a file, read the selected filename // and set it to the textbox var filename = $(this).val(); $('#fileName') ... -
MVC 3 html.TextBoxFor readonly要动态设置的属性(MVC 3 html.TextBoxFor readonly Properties to be set dynamically)[2022-06-03]
如果我正确理解你的问题,这可以用一个小小的JavaScript来完成。 这是一个简单的例子。 在页面加载时将每个文本框渲染为只读: <%: Html.TextBoxFor(model => model.Date, new { @readonly = "readonly" }) %> 为您的编辑按钮添加一个单击处理程序,该处理程序将从每个文本框中删除readonly属性: $("#editButton").click(function() { $("#Date").removeAttr("reado ...