728x90

-replace, replaceAll(문자열A,문자열B) 

ex) 문자열C.replace(문자열A,문자열B); 은   ,  문자열C내부의 문자열A를 문자열B로 치환하여  결과를 반환합니다.

 

-innerHTML

문자열내에 html태그가 있을 경우 , html태그는 HTML로 파싱하여준다.

 

하단은 통합검색시 이용하는 자바스크립트 명령어로 , 입력한 텍스트(inputText)를 색칠 해준다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function colorizeText(inputText, inputType) {
    /*select specified things*/
    var items;
    if (inputType == "subject") {
        items = document.getElementsByClassName("subject");
    } else if (inputType == "all") {
        items = document.getElementsByClassName("all");
    } else if (inputType == "name") {
        items = document.getElementsByClassName("name");
    } else {
        return;
    }
 
    for (var i = 0; i < items.length; i++) {
        var item_text = items[i].textContent;
        item_text = item_text.replaceAll(inputText,
                '<span style="background-color:#F4F895;">'
                        + inputText + '</span>');
        items[i].innerHTML = item_text;
    }
}
cs

 

하단은 검색으로 1을 입력 해보았을 경우이다.

'21년이전 > front-end' 카테고리의 다른 글

html - disabled , readOnly 의 차이  (0) 2021.06.06
js - 숫자 앞에 0을 붙이기  (0) 2021.06.06
js - var, let , const  (0) 2021.06.06
front - jquery ajax (동기식)  (0) 2021.06.04
front - modal  (0) 2021.06.04
728x90

html 태그의 기본 속성중  , disabled와 readOnly 가 있다.

 

공통점 :  두개다 사용자가 쓰기기능을 못하게 하고 오직 읽는 것만 가능하게 해준다.

 

차이점 : form 태그를 통해서 Server로 데이터를 전송하려 할때 , 

disabled="disabled" 된 태그는 읽혀 지지 않는다.

반면 , readOnly 가 지정된 태그는 읽혀 진다!

'21년이전 > front-end' 카테고리의 다른 글

js - 특정 문자열에 칼라주기.  (0) 2021.06.11
js - 숫자 앞에 0을 붙이기  (0) 2021.06.06
js - var, let , const  (0) 2021.06.06
front - jquery ajax (동기식)  (0) 2021.06.04
front - modal  (0) 2021.06.04
728x90
1
2
3
4
function numberPad(n, width) {
        n = n + '';
        return n.length >= width ? n : new Array(width - n.length + 1).join('0'+ n;
}
cs

1 : parameter는 정수와 0을포함한 정수의 길이이다 (ex 001 은 width 가 3)

2 : n을 문자열로 만든다.

3 : new Array(숫자) 가 의미 하는 것은 배열의 노드를 숫자 만큼 만들어 주겠다는 의미이고 ,

배열객체.join(문자) 의  의미는   ,  생성된 배열 노드 노드 사이마다  문자 를 넣어주겠다는 의미이다.

 

참고 

알고리즘 참고 : https://matthew-jo.tistory.com/8 

js에서 배열을 생성하는 방법 : https://gent.tistory.com/294 

배열 객체.join : http://blog.naver.com/diceworld/220213913009 

 

'21년이전 > front-end' 카테고리의 다른 글

js - 특정 문자열에 칼라주기.  (0) 2021.06.11
html - disabled , readOnly 의 차이  (0) 2021.06.06
js - var, let , const  (0) 2021.06.06
front - jquery ajax (동기식)  (0) 2021.06.04
front - modal  (0) 2021.06.04
728x90

var -    변수 재선언 가능  ,근본없음   

let -     변수 재선언 불가 , 변수값변경가능

const - 변수 재선언 불가 ,  변수값변경불가능(상수화)

 

자세한 설명과 호이스팅내용등 설명은 하단을 참고하도록 한다.

https://velog.io/@bathingape/JavaScript-var-let-const-%EC%B0%A8%EC%9D%B4%EC%A0%90

'21년이전 > front-end' 카테고리의 다른 글

html - disabled , readOnly 의 차이  (0) 2021.06.06
js - 숫자 앞에 0을 붙이기  (0) 2021.06.06
front - jquery ajax (동기식)  (0) 2021.06.04
front - modal  (0) 2021.06.04
css - box-shadow  (0) 2021.06.03
728x90

ajax는 비동기식 뿐만 아니라 동기식으로 처리해야할 경우도 생긴다.

대표적인 경우가 ajax 결과를 또다른 함수에서 리턴받아 이어서 작업해야하는 경우이다.

요점으로는,

1. async=false 로 지정해주어야 하며 ,

2. 콜백함수단위에서 데이터를 리턴하는 것이 아닌 ajax 전체 펑션단위에서 데이터를 리턴해야 한다.

 

하단의 주소에서 이에 대해 자세히 설명해주고 있다.

https://recollectionis.tistory.com/167

'21년이전 > front-end' 카테고리의 다른 글

js - 숫자 앞에 0을 붙이기  (0) 2021.06.06
js - var, let , const  (0) 2021.06.06
front - modal  (0) 2021.06.04
css - box-shadow  (0) 2021.06.03
html - input type  (0) 2021.06.03
728x90

- 구현 

 

하단은 html modal샘플이다

1
2
3
4
5
6
7
8
9
<!-- modal -->
<div class="modal hidden">
  <div class="modal__overlay"></div><!-- 외부클릭시 닫을 용도 ,외부색깔담당 -->
  <div class="modal__content">
    <div id="modal__text">사용 가능한 아이디입니다.</div>
    <button class="modal-button" style="background-color: #2E9AFE;" id="modal_close">OK</button>
  </div>
</div>
<!-- //modal -->
cs

하단은 modal 전용 css 이다

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.modal__overlay {
  position: absolute;
  background-color: rgba(0, 0, 0, 0.6);
  width: 100%;
  height: 100%;
}
.modal__content {
  position: relative;
  top: 0px;
  box-shadow: 1px 10px 20px rgba(0, 0, 0, 0.19), 1px 6px 6px rgba(0, 0, 0, 0.23);
  width: 20rem;
  background-color:white;
  text-align: center;
  padding: 1rem;
  border-radius: 10px;
}
.modal-button{
    margin-top:0.2rem;
    padding:0.6rem 2rem;
    hegith:1.2rem;
    font: normal normal bold 1rem arial;
    color:white;
}
.hidden {
  display: none;
}
cs

17 : modal__content 클래스는 모달창을 설정한다.

해당 코드를 빌려다가 쓰는 사람의 경우엔 , modal__content 클래스의 box-shadow , width만 변경해서 사용하면 될듯하다.

 

하단은 javascript 코드이다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<script>
~~~
openModal(); 
~~~
 
//modal
const closeBtn = document.getElementById('modal_close');
const modal = document.querySelector('.modal');
const overlay = document.querySelector('.modal__overlay');
const openModal = function(){
  modal.classList.remove('hidden');
}
const closeModal = function(){
  modal.classList.add('hidden');
closeBtn.addEventListener('click', closeModal);
overlay.addEventListener('click', closeModal);
</script>
cs

3 : openModal(); 을 원하는 자바스크립트 명령어 사이에 넣어주면 , 모달이 나온다.

 

하단의 이미지는 샘플 결과이다.

 

 

참고 및 수정 - https://github.com/eotkd4791/JavaScript/tree/main/Vanilla_JS/Modal

'21년이전 > front-end' 카테고리의 다른 글

js - var, let , const  (0) 2021.06.06
front - jquery ajax (동기식)  (0) 2021.06.04
css - box-shadow  (0) 2021.06.03
html - input type  (0) 2021.06.03
jsp - 태그 입력방지 , 줄바꿈 적용  (0) 2021.06.03
728x90

- box-shadow

지정 요소를 기준으로 그림자가 만들어지게하는 css 명령어

 

-문법 (  '()' 는 설명 ,  '[]'는 생략가능 표시 , 하단방향이 양의 y축방향이고 우측방향이 양의 x축방향입니다. )

box-shadow: offset-x(기준요소로부터의 x축거리 offset-y(기준요소로부터의 y축거리
   [blur-radius(블러되는 정도이지만, 그림자크기에 비례해 사이즈도 커짐)]   

[spread-radius(그림자의 크기에 비례)]    color(그림자의 색깔);

 

자주사용 되는 경우의 코드는 아래 두가지 경우일 거라고 생각한다.
1. box-shadow: offset-x offset-y blur-radius color;
2. box-shadow: offset-x offset-y blur-radius spread-radius color;

 

 콤마(,)를 이용한 명령어 구분으로 그림자 두겹도 된다..
box-shadow: 3px 3px red, -1em 0 .9em olive;

 

 

-추가가능옵션

 inset : 외부그림자가 아닌 내부그림자로 만듬

 

-글로벌 키워드(아직 안써봄)

box-shadow: inherit;
box-shadow: initial;
box-shadow: unset;

 

-참고

https://developer.mozilla.org/ko/docs/Web/CSS/box-shadow

728x90

-input type="tel"

pattern 와 함께 사용되어 010-1234-6867 같은 규약을 만들수 있다.

 

하단은 샘플이다

1
2
3
4
5
<form action="/action_page.php">
  <input type="tel" name="phone" placeholder="010-1234-5678" pattern="[0-9]{3}-[0-9]{4}-[0-9]{4}" required><br><br>
  <small>Format: 123-45-678</small><br><br>
  <input type="submit">
</form>
cs

2 :  pattern 을 보면  [ ] 내부는 올 수 있는 숫자의 범위를 지정하고 , {}내부는 []에 들어올 수 있는 숫자의 갯수,

-는 숫자뭉치간 이어지는 약속표기이다.

 

하단의 이미지는 , 사용자가 규약을 지키지 않고 서버로 url을 요구할 경우( submit 버튼이 눌릴떄 ) 나타나는 에러이다.

참고 : https://www.w3schools.com/tags/att_input_type_tel.asp

'21년이전 > front-end' 카테고리의 다른 글

front - modal  (0) 2021.06.04
css - box-shadow  (0) 2021.06.03
jsp - 태그 입력방지 , 줄바꿈 적용  (0) 2021.06.03
html - Form 태그 바깥에서 Form 내부 데이터들 서버로 전송하기  (0) 2021.06.01
js - 속성선택자  (0) 2021.05.31
728x90

- 사용자의 태그 입력 방지

1
2
<c:set var="item" value="${fn:replace(server->client로 오는 객체,'<','&lt;')}" />
<c:set var="item" value="${fn:replace(item,'>','&gt;')}" />
cs

- 줄바꿈 적용 

client - > server로 줄바꿈이 저장될때는 "\n" 형태로 저장이 된다. 

client에서 줄바꿈을 나타낼때는 "\n"을 "<br/>" 로 변경해주어야 한다.

 

서버단 부분

1
model.addAttribute("enter""\n");//개행문자처리
cs

프론트단 부분

1
2
3
4
<c:set var="commentcontent" value='${fn:replace(객체,enter,"<br>")}'/>
~
<div style="width:90%;">${commentcontent}</div>
~
cs

 

참고로, textarea는 태그가 아예안먹고 줄바꿈도 자동으로 알아서 해준다.

div내부텍스트나 type="text"의 내부텍스트는 태그가먹음...
다만! div 나 type="text"더라도 value안에 텍스트를 넣으면 태그가 안먹게됨!

'21년이전 > front-end' 카테고리의 다른 글

css - box-shadow  (0) 2021.06.03
html - input type  (0) 2021.06.03
html - Form 태그 바깥에서 Form 내부 데이터들 서버로 전송하기  (0) 2021.06.01
js - 속성선택자  (0) 2021.05.31
front - textarea  (0) 2021.05.27
728x90

방법은 매우 간단하지만,  꼭 필요한 상황이 아니면 유지보수의 원활함을 위해서 지양하는게 좋을것 같다.

 form태그에 id를 지정해주고

form바깥에 있는 type="submit"을 가진 element에

해당 form의 id를 form속성을 만들어서 값으로 넣어주면 된다.

 

하단의 예시는 직접 사용해본 샘플이다.

1
2
3
4
5
<form id="clientToServerText" action="contentView/registerComment" method="post" onsubmit="return emptyContentCheck()">
                <input type="hidden" name="bidx" value="${itboardDTO.bidx}"/>
                <input type="hidden" name="currentPage" value="${currentPage}"/>
</form>
<input form="clientToServerText" type="submit" value="댓글등록" class="BlackWhite unloginSet"style="width:24%; height:6vh; font-size:1rem;"/>
cs

form 태그 외부의  submit 버튼이 잘 작동된다.

 

'21년이전 > front-end' 카테고리의 다른 글

html - input type  (0) 2021.06.03
jsp - 태그 입력방지 , 줄바꿈 적용  (0) 2021.06.03
js - 속성선택자  (0) 2021.05.31
front - textarea  (0) 2021.05.27
Front - (CSS) float  (0) 2021.05.02

+ Recent posts