是否可以添加自定义Html属性? [英] Is it alright to add custom Html attributes?

查看:105
本文介绍了是否可以添加自定义Html属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,我正在工作,我想要标记,如果一行数据已更改。
如果在该行中更改了某个内容,我将使用自定义属性
标记该属性。

I have a site I'm working on where I want to mark if a row of data has been changed. If something has been changed in that row I would mark it with a custom attribute like so.

<tr>
  <td isDirty="true">
     ....row data
  <td>
</tr>

这对jQuery非常有用,它不会为我的页面添加太多代码。

This works great with jQuery and it doesn't add to much code to my page.

但是这是真正的做正确的方式,这样做和什么是缺点?

But is this really the correct way of doing something like this and what are the downsides?

我想另一种方式这样做会是这样,但似乎过度杀死。

I guess another way of doing this would be like this, but it seems like over kill.

<tr>
  <td>
     ....row data
     <input id="isDirty" type="hidden" value="true" />
  <td>
</tr>


推荐答案

为什么不使用jQuery数据能力?

Why don't you use the jQuery data capability?

您的示例将是(我不知道选择正确td的条件):

Your example will be (I don't know the condition to select proper td):

$("tr td").data("isDirty", true);

查看文档

这篇关于是否可以添加自定义Html属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆