gpt4 book ai didi

jquery - 使用 jQuery 元数据 - 无法读取 HTML5 数据属性

转载 作者:太空狗 更新时间:2023-10-29 15:26:28 26 4
gpt4 key购买 nike

我正在尝试使用 HTML5 数据属性并使用 jQuery 插件读取它们。

首先,DOCTYPE 在这种情况下重要吗? (我不担心验证)

这是我正在尝试做的事情:

<ul id="quiz">
<li data-career="math" class="first">
<span>Question 1</span>
<input type="radio" name="question1" />
<input type="radio" name="question1" />
<input type="radio" name="question1" />
</li>
<li data-career="science">
<span>Question 2</span>
<input type="radio" name="question2" />
<input type="radio" name="question2" />
<input type="radio" name="question2" />
</li>
</ul>

然后THIS 抛出一个错误(a is undefined)

$.metadata.setType("html5");
$(document).ready(function() {
var data = $("#quiz .first").metadata();
console.log(data);
});

还有 console.log(data.career) 也不起作用。

我正在使用 jQuery 1.4.2。

附言元数据现在是否作为 jQuery 的一部分包含在内?

最佳答案

自 1.4.3 HTML 5 起 data attribute得到了支持。

来自发行说明:

For example, given the following HTML:

<div data-role="page" data-hidden="true" data-options='{"name":"John"}'></div>

All of the following jQuery code will work.

$("div").data("role") === "page";
$("div").data("hidden") === true;
$("div").data("options").name === "John";

关于jquery - 使用 jQuery 元数据 - 无法读取 HTML5 数据属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5083938/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com