색상 변경 방법: 버튼 사용
P粉111927962
P粉111927962 2023-09-05 16:38:19
0
1
543
<p>이 함수에 더 적은 수의 코드를 작성할 수 있는 방법이 있나요? 버튼 중 하나를 누를 때 두 가지 색상 사이를 전환하고 싶습니다. green() 함수는 red와 정반대입니다. </p> <pre class="lang-html Prettyprint-override"><code><h1 id="header">빨간색 또는 녹색</h1> <button id="redButton" onclick="red()">빨간색 <button id="greenButton" onclick="green()">녹색 <pre class="brush:php;toolbar:false;">function red() { document.getElementById("header").innerHTML = "빨간색" document.getElementById('header').style.color = "빨간색" document.getElementById('redButton').style.color = "흰색" document.getElementById('redButton').style.BackgroundColor = "빨간색" document.getElementById('greenButton').style.color = "검은색" document.getElementById('greenButton').style.BackgroundColor = "회색" }</pre></p>
P粉111927962
P粉111927962

모든 응답(1)
P粉254077747

으아악 으아악 으아악
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿