HTML中的数据输入是什么?

发布于 2025-02-05 18:37:26 字数 172 浏览 4 评论 0 原文

<!DOCTYE html>
<html lang="ae-ar">
<head data-info="f:msnallexpuser,muiflt13cf">

我不理解上述数据信息的功能

<!DOCTYE html>
<html lang="ae-ar">
<head data-info="f:msnallexpuser,muiflt13cf">

I am not understand the function of data info above

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初相遇 2025-02-12 18:37:28

数据 - * html中的属性存储自定义值。该存储的数据可以在JavaScript中检索。在您的情况下, data-info 是属性名称,其值为 f:msnallexpuser,muiflt13cf 。可以在JavaScript中使用 getAttribute 函数检索值。

data-* attribute in HTML stores custom values. This stored data can be retrieved in JavaScript. In your case, data-info is the attribute name and its value is f:msnallexpuser,muiflt13cf. Value can be retrieved using getAttribute function in JavaScript.

燃情 2025-02-12 18:37:28

“ HTML5的设计具有可扩展性的数据,应与特定元素关联但不需要任何定义的含义。数据 - *属性允许我们在没有其他黑客的标准语义,语义HTML元素上存储额外的信息非标准属性或DOM上的额外属性。” -

您可以使用 el。 getAttribute('data-whate')要在JavaScript中获取数据属性,但是获取HTML数据属性的更好方法是使用 el.dataset.thythy ,你想要。

您还可以使用 content:attr(data-whit why/code>或selector: [data-white ='value'] content:attr(data-whit whither)中获取数据属性。 > [data-whith]

"HTML5 is designed with extensibility in mind for data that should be associated with a particular element but need not have any defined meaning. data-* attributes allow us to store extra information on standard, semantic HTML elements without other hacks such as non-standard attributes, or extra properties on DOM." - MDN

You could use el.getAttribute('data-whatever') to get the data attribute in JavaScript however a better way to get the HTML data attribute is to use el.dataset.whatever, whatever being what-ever you want.

You can also get data attributes in CSS as well using the content: attr(data-whatever) or the selector: [data-whatever='value'] or [data-whatever]

七色彩虹 2025-02-12 18:37:28

我认为我从

function showDetails(animal) {
  var animalType = animal.getAttribute("data-animal-type");
  alert("The " + animal.innerHTML + " is a " + animalType + ".");
}
<h1>Species</h1>
<p>Click on a species to see what type it is:</p>

<ul>
  <li onclick="showDetails(this)" id="owl" data-animal-type="bird">Owl</li>
  <li onclick="showDetails(this)" id="salmon" data-animal-type="fish">Salmon</li>  
  <li onclick="showDetails(this)" id="tarantula" data-animal-type="spider">Tarantula</li>  
</ul>

如果您想要定义和用法,则我还为您复制并粘贴了它。

数据 - *属性用于将自定义数据私有到页面
或应用程序。

数据 - *属性使我们能够嵌入自定义数据
所有HTML元素上的属性。

然后可以在页面的JavaScript中使用存储(自定义)数据
创建更具吸引力的用户体验(没有任何AJAX呼叫或
服务器端数据库查询)。

数据 - *属性由两个部分组成:

属性名称不得包含任何大写字母,必须
至少在前缀“ data-”属性之前长达一个字符
值可以是任何字符串注意:自定义属性,前缀为“ data-”
用户代理将完全忽略。

数据 - *属性是一个全局属性,可用于任何
html元素。

谢谢,最好的问候!

I think the below code which I copied from W3Schools HTML data-* Attribute tutorial will help you to understand it easily.

function showDetails(animal) {
  var animalType = animal.getAttribute("data-animal-type");
  alert("The " + animal.innerHTML + " is a " + animalType + ".");
}
<h1>Species</h1>
<p>Click on a species to see what type it is:</p>

<ul>
  <li onclick="showDetails(this)" id="owl" data-animal-type="bird">Owl</li>
  <li onclick="showDetails(this)" id="salmon" data-animal-type="fish">Salmon</li>  
  <li onclick="showDetails(this)" id="tarantula" data-animal-type="spider">Tarantula</li>  
</ul>

If you want the definition and usage, for it, I also have copied and pasted it for you.

The data-* attribute is used to store custom data private to the page
or application.

The data-* attribute gives us the ability to embed custom data
attributes on all HTML elements.

The stored (custom) data can then be used in the page's JavaScript to
create a more engaging user experience (without any Ajax calls or
server-side database queries).

The data-* attribute consist of two parts:

The attribute name should not contain any uppercase letters, and must
be at least one character long after the prefix "data-" The attribute
value can be any string Note: Custom attributes prefixed with "data-"
will be completely ignored by the user agent.

The data-* attribute is a Global Attribute, and can be used on any
HTML element.

Thanks and best regards!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文