简体   繁体   English

访问HTML自定义属性

[英]Accessing HTML custom attributes

I want to know is there any way to add a custom attribute to the a HTML element. 我想知道有没有办法将自定义属性添加到HTML元素。

For example , 例如 ,

<input type="text" name="txtNAME1" displayName="dname1" />

In the above example the custom attribute "displayName" is not a standard HTML attribute. 在上面的示例中,自定义属性“displayName”不是标准HTML属性。 So I want to know if I can define the same and push the intended value to the server and access the same attribute's value. 所以我想知道我是否可以定义相同的内容并将预期值推送到服务器并访问相同属性的值。

Thanks in advance! 提前致谢!

Which language are you using? 你使用哪种语言? You can do this in C# using 你可以在C#中使用

<input type="text" name="txtNAME1" displayName="dname1" runat="server" id="test" />

Then, in the code behind: 然后,在后面的代码中:

test.Attributes["displayName"];

You can also access it in jQuery with 您也可以使用jQuery访问它

$('test').attr('displayName')

and send it through to the server via a handler. 并通过处理程序将其发送到服务器。

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

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