是否所有HTML标记都支持name属性,或者只有少数人可以使用name属性?此外,所有标签都支持title属性吗?
我问的原因是因为我需要在这些属性中存储有关当前元素的信息.这是一个例子:
<img src="example-image.jpg" alt="Example Image" title="Additional Information" name="Even more info"/>
<div class="example-word" title="Information about this tag" name="More information about this tag">Word</div>
我存储在属性中的这些附加信息将通过javascript获取.
根据MDN name
官方仅适用于以下元素:<a>, <applet>, <button>, <form>, <frame>, <iframe>, <img>, <input>, <map>, <meta>, <object>, <param>, <select>, and <textarea>
- 基本上形成字段,链接和插件对象.
如果要使用元素存储其他信息(元数据),则应查看data-
属性.这是HTML5的推荐方法,但也适用于旧版浏览器.这也意味着您可以根据需要存储尽可能多的不同数据
<img src="example-image.jpg" alt="Example Image" title="Additional Information"
data-name="Even more info" data-other-info="Some other information" />
<div class="example-word" title="Information about this tag"
data-name="More information about this tag">Word</div>
Run Code Online (Sandbox Code Playgroud)