Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- springbatch
- JPA Insert
- step 테이블
- Spring Entity
- spring security
- react forwardRef
- 코드 중복제거
- Spring JPA
- 텍스트가 많은 경우
- spring
- react link
- javascript 함수
- react jsx if
- Spring DTO
- react Page
- editor Quill
- JPA Update\
- react Quill
- react
- javascript 기초
- SpringBatch 스키마
- react quill custom
- react react-router-dom v6
- spring builder
- javascrpit 기초
- Spring Controller return
- springbatch chunk
- Docker Windows 설치
- Javascript
- Spring CORS
Archives
- Today
- Total
천천히 알아보는 코딩공부
javascript 랜덤 본문
javascript 랜덤으로 배열에있는 문자열 출력
const quotes = [
{
quote : "a",
author : "daeseok1",
},
{
quote : "b",
author : "daeseok2",
}
]
const quote = document.querySelector("#quote span:first-child");
const author = document.querySelector("#quote span:last-child");
const todaysQuote = quotes[Math.floor(Math.random() * quotes.length)]
quote.innerText = todaysQuote.quote; //quote 위치에 랜덤 quote 출력
author.innerText = todaysQuote.author; //author 위치에 랜덤 author 출력
- a daeseok1, b daeseok2 중 결과값이 랜덤으로 출력된다.
javascript 랜덤으로 배열에있는 이미지 출력
const images = ["1.jpg", "2.jpg", "3.jpg"]
const chosenImage = images[Math.floor(Math.random() * images.length)]
const bgImage = document.createElement("img");
bgImage.src = `img/${chosenImage}`
document.body.appendChild(bgImage);
'JavaScript > 예제' 카테고리의 다른 글
javascript to do 리스트 응용 (3) localstorage 데이터 삭제 (0) | 2022.04.06 |
---|---|
javascript to do 리스트 응용 (1) 만들기/삭제/localstorage 저장 (0) | 2022.04.03 |
Comments