
DOMElement::toggleAttribute 메서드는 attribute 이름과 값을 받아서 해당 속성을 추가하거나 제거하는 역할을 합니다.
이 메서드는 attribute 이름을 기준으로 동작합니다.
예를 들어, 버튼의 disabled 속성을 토글하려면 attribute 이름이 'disabled' 인 속성을 토글합니다.
toggleAttribute 메서드는 attribute 이름이 'disabled' 인 속성을 추가하거나 제거하는 역할을 합니다.
속성이 이미 존재하는 경우, toggleAttribute 메서드는 속성을 제거합니다.
속성이 존재하지 않는 경우, toggleAttribute 메서드는 속성을 추가합니다.
따라서, 다음 코드를 사용하여 버튼의 disabled 속성을 토글할 수 있습니다.
#hostingforum.kr
php
$button = $dom->createElement('button');
$button->setAttribute('disabled', 'true');
$button->toggleAttribute('disabled', true); // disabled 속성을 제거합니다.
$button->toggleAttribute('disabled', true); // disabled 속성을 추가합니다.
또한, toggleAttribute 메서드는 attribute 이름이 'disabled' 인 속성을 토글할 때, 속성의 값은 무시됩니다.
속성의 값은 toggleAttribute 메서드의 동작에 영향을 주지 않습니다.
따라서, 다음 코드를 사용하여 버튼의 disabled 속성을 토글할 수 있습니다.
#hostingforum.kr
php
$button = $dom->createElement('button');
$button->setAttribute('disabled', 'true');
$button->toggleAttribute('disabled', 'false'); // disabled 속성을 제거합니다.
$button->toggleAttribute('disabled', 'false'); // disabled 속성을 추가합니다.
2025-06-28 19:44