221226-자바스크립트

조이연·2022년 12월 26일
0

JSP

목록 보기
9/19

[1]

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>문자열 다루기</title>
</head>
<body>
    <script>
        const str="hello 자바와 자바스크립트";
        console.log(str.includes('h'));
        console.log(str.indexOf(' '));
        console.log(str.lastindexOf(' '));
        //첫번째부터 두번째까지 
        console.log(str.substring(1,4));
        //첫번재부터 4개
        console.log(str.substr(1,4));
        //매개변수를 하나만 주면 끝까지 자른다.
        console.log(str.substr(5));

        const ar=[1,3,5];
        //Java에서 contains
        console.log(ar.includes(4));
        console.log(ar.includes(3));
    </script>
</body>
</html>

[2]

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="http://ajax.googleapis.com/ajax/libbs/jquery.min.js"></script>
    <titlec>프사처리하기</title>
</head>
<body>
    <input type="file" id="profile"> 
    <!--multiple: 컨트롤 키 누르고 여러 개 선택 가능 but 사용자들이 사용하기 쉽지 않아 잘안쓴다. -->
    <button id="choice">선택</button>
    <script>
        $('#choice').on('click', function() {
            //input type="file" id="profile"
            console.log($('#profile')[0].files[0]);
             //배열아니고->속성 jQuery객체는 0이라는 속성을 가진다 그 속성은 html 태그

             //선택한 파일이름을 출력하시오.
             const name = $('#profile')[0].files[0].name;
             console.log(name);

             //파일 name이 '내 이력서 최종.xlsx'라면 'spring.xlsx'로 바꿔주자
             const lastindexOfDot=name.lastindexOfDot('.');
             const ext=name.subtr(lastindexOfDot);
             console.log("spring"+ext);
        }
    </script>
    
</body>
</html>
profile
안녕하세요

0개의 댓글