jQuery 1일차. jdk, eclipse, tomcat, jquery를 다운받아서 사용했다.
jQuery를 사용하면 JavaScript 코드를 간결하게 작성할 수 있다.
<body> <h1>JavaScript 실습</h1> <button onClick="set_h1()">h1 태그 문자열 변경</button> </body>
JavaScript로 작성한 set_h1() 함수
function set_h1() { let h1 = document.getElementsByTagName("h1"); let str = h1[0].firstChild; str.nodeValue = "JavaScript로 문자열 변경"; }
jQuery로 작성한 set_h1() 함수
function set_h1() { $("h1").text("jQuery로 문자열 변경"); }
eclipse에서 html 파일을 실행시키다가 아래 그림과 같은 에러가 발생했다.
이 에러가 발생하면 파일이 있는 프로젝트를 우클릭해서 Properties를 클릭하거나 Alt+Enter를 입력한다.
그러면 Server 탭이 있을텐데 여기서 <None>이 선택되어있을 것이다. 이걸 내가 사용하고자하는 서버로 선택한 후 Apply and Close를 하면 제대로 작동할 것이다.