1. 程式人生 > >React 標籤和屬性支援

React 標籤和屬性支援

來源

React 嘗試支援所用常用的元素。

一、HTML 元素

下列的 HTML 元素是被支援的:

a abbr address area article aside audio b base bdi bdo big blockquote body br button canvas caption cite code col colgroup data datalist dd del details dfn dialog div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hr html i iframe img input ins kbd keygen label legend li link main map mark menu
menuitem meta meter nav noscript object ol optgroup option output p param picture pre progress q rp rt ruby s samp script section select small source span strong style sub summary sup table tbody td textarea tfoot th thead time title tr track u ul var video wbr

二、SVG 元素

下列的 SVG 元素是被支援的:

circle
defs ellipse g line linearGradient mask path pattern polygon polyline radialGradient rect stop svg text tspan

你或許對 react-art 也感興趣,它是一個為 React 寫的渲染到 CanvasSVG 或者 VML(IE8) 的繪相簿。

三、支援的屬性

React 支援所有 data-*aria-* 屬性,也支援下面列出的屬性。

注意: 所有的屬性都是駝峰命名的,class 屬性和 for 屬性分別改為 className 和 htmlFor,來符合 DOM API 規範。

1、HTML 屬性

這些標準的屬性是被支援的:

accept acceptCharset accessKey action allowFullScreen allowTransparency alt async autoComplete autoPlay cellPadding cellSpacing charSet checked classID className cols colSpan content contentEditable contextMenu controls coords crossOrigin data dateTime defer dir disabled download draggable encType form formAction formEncType formMethod formNoValidate formTarget frameBorder height hidden href hrefLang htmlFor httpEquiv icon id label lang list loop manifest marginHeight marginWidth max maxLength media mediaGroup method min multiple muted name noValidate open pattern placeholder poster preload radioGroup readOnly rel required role rows rowSpan sandbox scope scrolling seamless selected shape size sizes span spellCheck src srcDoc srcSet start step style tabIndex target title type useMap value width wmode

2、另外,下面非標準的屬性也是被支援的:

autoCapitalize autoCorrect 用於移動端的 Safari。
property 用於 Open Graph 原標籤。
itemProp itemScope itemType 用於 HTML5 microdata。

3、也有 React 特有的屬性 來源

key:可選的唯一的標識器。當元件在渲染過程中被各種打亂的時候,由於差異檢測邏輯,可能會被銷燬後重新建立。給元件繫結一個 key,可以持續確保元件還存在 DOM 中。

ref:獲取真實dom時使用,this.refs.[refName].getDOMNode()。

dangerouslySetInnerHTML:提供插入純 HTML 字串的功能,主要為了能和生成 DOM 字串的庫整合。

4、SVG 屬性

cx cy d dx dy fill fillOpacity fontFamily fontSize fx fy gradientTransform gradientUnits markerEnd markerMid markerStart offset opacity patternContentUnits patternUnits points preserveAspectRatio r rx ry spreadMethod stopColor stopOpacity stroke strokeDasharray strokeLinecap strokeOpacity strokeWidth textAnchor transform version viewBox x1 x2 x y1 y2 y