Latest web development tutorials

Metoda DOM Element setAttribute ()

Elementy obiektu obiekt elementu

Przykłady

Ustaw atrybut type elementu wejściowego:

document.getElementsByTagName("INPUT")[0].setAttribute("type","button");

Ustawianie właściwości temu:

Otoczenie:


Spróbuj »

Definicja i Wykorzystanie

Metoda setAttribute (), aby utworzyć lub zmienić nową właściwość.

Jeśli określony atrybut już istnieje, tylko ustawić wartość.


Pomoc Browser

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Metoda Wszystkie główne przeglądarki obsługują setAttribute ()

Internet Explorer 8 i wcześniejsze wersje IE nie obsługuje tej metody.


gramatyka

element .setAttribute( attributename , attributevalue )

parametry

参数 类型 描述
attributename String 必须。你要添加的属性名称。
attributevalue String 必须。你要添加的属性值。

Wartość zwracana

Nie zwraca wartości.

dane techniczne

wersja DOM Poziom podstawowy 1 Element obiektu


Elementy obiektu obiekt elementu