본문 바로가기

javascript/sample

jquery Math.random값 사용하기

jquery Math.random값 사용하기


CSS


<style>
body{ margin:0; padding:0; }
.number{ text-align: center; font-size:20px; color: #000;}
</style>


SCRIPT


<script>
var list = [ 1, 2, 3, 4, 5, 6 ]
var len = list.length + 1;
var dataText = $( ".number" );
dataText.text( Math.floor( Math.random() * len ) );
</script>


HTML


<p class="number"></p>


새로고침 될때마다 .number에 텍스트값이 랜덤으로 변경 된다.

'javascript > sample' 카테고리의 다른 글

jquery 슬라이더  (0) 2018.06.28
jquery 별점 체크  (0) 2018.06.27
이전 버튼 다음 버튼 클릭 시 해당 녀석 찾기  (0) 2018.05.17
자바스크립트 특정 날짜  (0) 2018.05.17
팝업 데이터로 불러오기  (0) 2018.04.13