[英]Will ASP.NET MVC's new “unobtrusive” JavaScript make my HTML code invalid?
In the past few months, I've read multiple articles about this new unobtrusive JavaScript approach in ASP.NET MVC. 在过去的几个月里,我在ASP.NET MVC中阅读了多篇关于这种新的不引人注目的JavaScript方法的文章。 You can read about it here.
你可以在这里读到它。
It basically puts everything into HTML attributes prefixed with data-...
, and last time I checked, the HTML specification did not allow things like this. 它基本上将所有内容放入带有
data-...
前缀的HTML属性中,并且上次我检查时,HTML规范不允许这样的事情。 (I do not care about HTML 5, as it is not complete yet.) (我不关心HTML 5,因为它尚未完成。)
My question is this: 我的问题是:
If I use this feature in my ASP.NET MVC application, it will make the HTML output of the application invalid, won't it? 如果我在ASP.NET MVC应用程序中使用此功能,它将使应用程序的HTML输出无效,不是吗? If this is the case, then what good does it do?
如果是这种情况,那它有什么用呢?
It never really bothered me that MVC put a few JavaScript stuff here and there. MVC在这里和那里放了一些JavaScript东西,这从来没有让我感到困扰。 But if my HTML output will be invalid, that will bother me quite much.
但是如果我的HTML输出无效,那将非常困扰我。
Yes, if you do not accept HTML5 as valid HTML, then it will indeed be "invalid." 是的,如果您不接受HTML5作为有效的HTML,那么它确实会“无效”。
data-*
attributes are new features of the HTML5 specification. data-*
属性是HTML5规范的新功能。
I would definitely suggest changing your attitude toward this though; 我肯定会建议改变你对此的态度; if you only worked with fully-completed standards, then make sure you're not using any CSS3 features, or anything cool like
<canvas />
, and the like! 如果您只使用完全完成的标准,那么请确保您没有使用任何CSS3功能,或者像
<canvas />
之类的任何酷炫之类的东西! Heck, even if you use innerHTML
in your JavaScript, that's not part of any standard DOM except that defined for HTML5! 哎呀,即使你在JavaScript中使用
innerHTML
,除了为HTML5定义之外,它不是任何标准DOM的一部分!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.