简体   繁体   English

mess属性有什么作用?

[英]What does the mess attribute do?

I saw this on a question recently. 我最近在一个问题上看到了这一点。

<input type="radio" mess="whats up" name="q1" value="A" class="correct"/>

I can't get what the mess attribute do, and I couldn't see any result on the internet. 我无法获得mess属性的作用,也无法在互联网上看到任何结果。 So what is the mess attribute for? 那么mess属性的作用是什么?

It can be called as custom attributes intended to store a piece of information (purely for developer puropse)but it not advisable. 可以将其称为用于存储一条信息的纯属定制属性 (仅供开发人员使用),但不建议使用。

Instead you can go for HTML5 custom data attribute like 相反,您可以使用HTML5 custom data attribute例如

data-mess="whats up"

It can be easily accessed with .data() in jQuery. 可以使用jQuery中的.data()轻松访问它。

<input type="radio" data-mess="whats up" name="q1" value="A" class="correct"/>

See 看到

$('.correct').data('mess') // to getch the value
$('.correct').data('mess', 'some value')  //to update the value

FYI:* custom data- ** is purely validated with w3c validator . 仅供参考:* custom data- **仅使用w3c验证程序进行验证 Whereas not with yours. 而不是你的。

It's just a way to store arbitrary data in the tag. 这只是在标签中存储任意数据的一种方法。 It does whatever the programmer intends it to do. 它会执行程序员打算执行的任何操作。 Some people prefer to add custom attributes via data-foo , others prefer this syntax. 有些人喜欢通过data-foo添加自定义属性,其他人则喜欢这种语法。

There is no mess attribute, in the question he just used it to attr and get the value through JQuery. 没有mess属性,在这个问题上,他只是用它来attr并通过JQuery获取值。

For example: 例如:

checked = $('input:checked').attr('mess'); sets checked to whatever the checked input had on the ' mess attribute', as seen in the question. 如问题所示,将checked设置为“ mess attribute”上已检查的输入所具有的内容

Another example: 另一个例子:

$('#BobDiv').attr('txt'); will return 'Bob' if your HTML is <div id = 'BobDiv' txt = 'Bob' /> 如果您的HTML是<div id = 'BobDiv' txt = 'Bob' />则将返回'Bob'

As seen here, you have to amend it in your !DOCTYPE declaration, though. 如此处所示您必须在!DOCTYPE声明中对其进行修改。

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

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