简体   繁体   English

如何将其转换为数据属性?

[英]How can I convert this into data-attributes?

I'm confused with data-attributes and my task is to convert this into a html5 valid code: 我对数据属性感到困惑,我的任务是将其转换为html5有效代码:

<xy:search campaign="campaign-name" width="280px" height="32px">
</xy:search> 

This is an advertisement and recently we wanted to validate our page but this is the last error I couldn't fix, because of the custom dtd element. 这是一个广告,最近我们想验证我们的页面,但这是我无法解决的最后一个错误,因为自定义dtd元素。

I don't want to write custom dtd file, and yes, this code must be work exactly like before changes, they have a script for this custom element, so I just want to modify the base code and "translate" it to the validator, so the element must be visible/readable somehow for the advertisor's script. 我不想编写自定义dtd文件,是的,此代码必须像更改前一样工作,它们具有此自定义元素的脚本,因此我只想修改基本代码并将其“翻译”到验证程序,因此该元素对于广告客户的脚本而言必须是可见/可读的。

I think it can be solved with html5 data-attributes, but I don't know that method... 我认为可以使用html5数据属性来解决,但我不知道该方法...

Any help would be appriciated. 任何帮助将被申请。

Assuming campaign it the only attribute you need to convert... it is as simple as prepending data- to the attribute. 假设campaign是您需要转换的唯一属性...就像将data-添加到属性一样简单。 That's all a data attribute is. 这就是数据属性。 Example: 例:

<xy:search data-campaign="campaign-name" width="280px" height="32px">

And then to access the value in something like jQuery, you would use .data() : 然后要使用类似jQuery的值,您可以使用.data()

$("your element").data("campaign"); // getter
$("your element").data("campaign","new value"); // setter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM