简体   繁体   中英

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. 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. (I do not care about HTML 5, as it is not complete yet.)

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? 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. But if my HTML output will be invalid, that will bother me quite much.

Yes, if you do not accept HTML5 as valid HTML, then it will indeed be "invalid." data-* attributes are new features of the HTML5 specification.

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! Heck, even if you use innerHTML in your JavaScript, that's not part of any standard DOM except that defined for HTML5!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM