简体   繁体   English

ASP.NET MVC的新“不引人注目的”JavaScript会使我的HTML代码无效吗?

[英]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.

相关问题 ASP.Net MVC 3 ViewModel,简洁的JavaScript和自定义验证 - ASP.Net MVC 3 ViewModel, unobtrusive JavaScript and custom validation 如何为HTML助手ASP.NET MVC编写Javascript代码? - How to write Javascript code for HTML helpers ASP.NET MVC? 结合 JavaScript 和 ASP.NET MVC HTML 代码问题 - Combining JavaScript and ASP.NET MVC HTML code issue ASP.NET MVC / Jquery Unobtrusive Ajax,在返回html数据后尝试检查元素是否加载了Jquery - ASP.NET MVC / Jquery Unobtrusive Ajax, trying to check if element is loaded with Jquery after the html data is returned ASP.Net MVC Razor引擎:如果用户输入了无效数据,请使用javascript函数 - ASP.Net MVC Razor engine: Make a javascript function aware if the user has input invalid data ASP.NET MVC中不引人注意的客户端验证仍然提交表单 - Unobtrusive Client Validation in ASP.NET MVC Still Submit Form 我应该在asp mvc中使用不显眼的javascript而不是编写我自己的验证码吗? - should i use unobtrusive javascript in asp mvc instead of writing my own validation code? 您可以混合使用ASP.Net和不干扰JavaScript吗 - Can you mix ASP.Net and Unobtrusive JavaScript 如何使用ASP.NET MVC将JavaScript变量传递给ASP代码 - How to pass javascript variable to asp code with ASP.NET MVC 在我的应用程序 asp.net mvc 的后台运行此 controller 和 javascript 代码 - run this controller and javascript code in background of my application asp.net mvc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM