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 |
Tags
- 텍스트가 많은 경우
- Spring CORS
- react react-router-dom v6
- spring
- react
- Javascript
- springbatch chunk
- react Quill
- springbatch
- javascrpit 기초
- react Page
- step 테이블
- 코드 중복제거
- Spring Entity
- react forwardRef
- react jsx if
- SpringBatch 스키마
- JPA Update\
- Spring Controller return
- Spring JPA
- javascript 함수
- Spring DTO
- spring security
- javascript 기초
- editor Quill
- JPA Insert
- react link
- react quill custom
- Docker Windows 설치
- spring builder
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