jQuery 및 Javascript를 사용하여 HTML에서 한 번에 모든 버튼의 InnerHTML을 변경하는 방법은 무엇입니까?

사용자 1556433

내 페이지에 5 개의 버튼이 있다고 가정합니다. 한 번에 버튼의 innerHTML을 어떻게 변경할 수 있습니까? "Clicked"텍스트가있는 I 버튼은 Change InnerHTML 버튼을 클릭하면 "Click me"로 변경됩니다.

<!DOCTYPE html>
<html lang="en">
  <head>
    <script type="text/javascript">
        function ChangeInnerHTML()
        {
            //Iterate all the buttons with innerHTML = "Clicked" in the DOM and set them to "Click me".
        }
    </script>
  </head>
  <body>
    <button type="button" id="myButton1">Click me</button>
    <button type="button" id="myButton2">Clicked</button>
    <button type="button" id="myButton3">Click me</button>
    <button type="button" id="myButton4">Clicked</button>
    <button type="button" id="myButton5">Click me</button>

    <button type="button" id="btnChangeInnerHTML" onclick="ChangeInnerHTML()">Change InnerHTML</button>

  </body>
 </html>
펠릭스

넌 할 수있어:

function ChangeInnerHTML() {
    $('button').each(function() {
        if ($.trim($(this).html()) == "Clicked") 
            $(this).html('Click me');
    });
}

바이올린 데모

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관