HtmlElement.SetAttribute(String, String) 메서드

정의

요소에서 명명된 특성의 값을 설정합니다.

public:
 void SetAttribute(System::String ^ attributeName, System::String ^ value);
public void SetAttribute (string attributeName, string value);
member this.SetAttribute : string * string -> unit
Public Sub SetAttribute (attributeName As String, value As String)

매개 변수

attributeName
String

설정할 특성의 이름입니다.

value
String

이 특성의 새 값입니다.

예제

다음 코드 예제에서는 이미지에 대 한 특성을 설정 SRC 하는 데 사용 하 여 SetAttribute 현재 문서에 새 IMG 요소를 추가 합니다.

private void InsertImageFooter()
{
    if (webBrowser1.Document != null)
    {
        HtmlDocument doc = webBrowser1.Document;
        HtmlElement elem = doc.CreateElement("IMG");
        elem.SetAttribute("SRC", "http://www.adatum.com/images/footer-banner.jpg");

        doc.Body.AppendChild(elem);
    }
}
Private Sub InsertImageFooter()
    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            Dim Elem As HtmlElement = .CreateElement("IMG")
            Elem.SetAttribute("SRC", "http://www.adatum.com/images/footer-banner.jpg")

            .Body.AppendChild(Elem)
        End With
    End If
End Sub

설명

HTML의 특성은 해당 요소에 유효한 이름-값 쌍입니다. HtmlElement 는 모든 요소에 공통적인 특성만 노출하고 특정 유형의 요소에만 적용되는 특성만 노출합니다. SRC 는 태그에 IMG 대해 미리 정의된 특성입니다(예: 태그에 DIV 대해서는 정의되지 않음). SetAttribute 관리되는 DOM(문서 개체 모델)에 노출되지 않은 특성을 사용하고 GetAttribute 조작합니다.

요소에 정의된 특성이 아닌 경우 attributeName 요소 SetAttribute 에서 해당 특성을 새 특성으로 정의합니다.

GetAttributeSetAttribute /소문자를 구분하지 않습니다.

To set the class attribute on an HtmlElement , you must refer to the attribute as className when specifying the first argument to SetAttribute

적용 대상

추가 정보