How to make Visual Studio Handle HTML 5 Tags without warning

眉间皱痕 提交于 2020-01-01 03:56:14

问题


I have various html tags (related to jquery mobile) that Visual Studio is flagging as not valid attributes: For exmaple:

<div data-role="page" id="my_id" data-theme="b" data-position="fixed">

Gets amongst others:

Validation (XHTML 1.0 Transitional): Attribute 'data-role'
is not a valid attribute of element 'div'

As you know, data-* are valid attributes of div in HTML 5.

I'm not sure how this is validated, though I think via DTDs and xmlns, so the head of the page is the default auto generated by Visual Studio:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

I know they are only warnings, but my experience is that if you leave lots of warnings that are invalid, then all the warnings that are valid get lost in the middle.

Is there any way to tell Visual Studio that these warnings should not be shown without completely disabling html validation?

(Visual Studio 2010 if it is relevant.)


回答1:


You should install the Web Standards Update and then switch to HTML5 as your default schema:

In addition, you should not use the XHTML 1.0 transitional opening incantation when using HTML 5 attributes. Instead, use the usual HTML5 one:

<!DOCTYPE html>
<html>



回答2:


In VS2012 will be enough do uncheck 'Use doctype for validation schema detection'.



来源:https://stackoverflow.com/questions/6447322/how-to-make-visual-studio-handle-html-5-tags-without-warning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!