如何向标签添加新属性 [英] How to add a new attribute to a tag

查看:257
本文介绍了如何向标签添加新属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<input  id="test" value="123" name ="test"  verify="NOTNULL">

在某些HTML中,我看到输入标签具有验证的属性。如何将其添加到输入标签?

In some HTML, I saw the input tag has the attribute verify. How to add it to the input tag?

我尝试过代码

alert(document.getElementById("test").verify)  

结果是未定义

如何向元素添加新属性?

How do I add a new attribute to the element?

推荐答案

如果你的意思是说html输入元素有一个 [verify] 属性,那么你可以通过 getAttribute()

If you mean to say that the html input element has a [verify] attribute, then you can access the attribute via getAttribute():

<input id="test" verify="test" />



JS:

JS:

document.getElementById('test').getAttribute('verify'); //test

这篇关于如何向标签添加新属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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