Categories: DOM对象tips

HTML DOM setAttribute() 方法 | DOM 对象:HTML DOM 元素对象

返回到:DOM 对象:HTML DOM 元素对象

定义和用法

setAttribute() 方法创建或改变某个新属性。

如果指定属性已经存在,则只设置该值。

所有主要浏览器都支持 setAttribute() 方法

Internet Explorer 8 及更早 IE 版本不支持该方法。

语法

element.setAttribute(attributename,attributevalue)

参数

参数类型描述
attributenameString必须。你要添加的属性名称。
attributevalueString必须。你要添加的属性值。

返回值

没有返回值。

技术细节

DOM 版本Core Level 1 Element Object

实例

设置 input元素的的属性类型:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Web176教程网(web176.com)</title>
</head>
<body>

<input value="OK">

<p id="demo">点击下面的按钮来设置按钮的类型属性。</p>
<button >

terry

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts