JS 의 다양한 알림 상자, 타이머, 정시 작업
11248 단어 JS
알림 상자: alert ("축하합니다. 등록 성공");
확인 상자: confirm ("삭제 하 시 겠 습 니까?");확인 상 자 는 boolean 값 을 되 돌려 줍 니 다. 확인 을 누 르 면 true 로 돌아 갑 니 다. 취 소 를 누 르 면 false var returnValue = confirm ("삭제 하 시 겠 습 니까?") 을 되 돌려 줍 니 다.alert ("되 돌아 오 는 값 을 누 르 면:" + returnValue);
입력 상자: prompt ("비밀 번 호 를 입력 하 십시오");입력 상 자 는 사용자 가 입력 한 값 을 되 돌려 줍 니 다. 사용자 가 아무런 데 이 터 를 입력 하지 않 으 면 비어 있 습 니 다. 그렇지 않 으 면 사용자 가 입력 한 데 이 터 를 되 돌려 줍 니 다. 취 소 를 누 르 면 null var returnValue = pormpt ("비밀 번 호 를 입력 하 십시오") 를 되 돌려 줍 니 다.alert ("입력 한 값 은:" + returnValue);
새 페이지 열기: open (")http://www.baidu.com"); open (" 연결 주소 "); 모두 window. open (" 링크 주소 ") 이 라 고 쓰 여 있 습 니 다.
타이머 1: setTimeout ("alert (" hi "), 1000), setTimeout (방법 체, 밀리초 수), 주의: 실행 할 때 방법 체 를 불 러 온 다음 1000 밀리초 후에 var name = setTimeout (" alert ("Hi JS"), "1000) 을 실행 합 니 다.
타이머 1: clearTimeout (타이머 이름) 을 닫 습 니 다. clearTimeout (name);
타이머 2: setInterval ("alert (" HI JS ");, 100); var name = setInterval (" alert ("HI JS"); ", 1000); setInterval (방법 체, 밀리초);
타이머 2: clearInterval (name) 을 닫 습 니 다.
<html>
<head>
<meta charset="UTF-8">
<title>js BOM---window title>
head>
<body>
<button onclick="alertDemo();" > button><br/>
<button onclick="confirmDemo();" > button><br/>
<button onclick="promptDemo();" > button><br/>
<button onclick="openDemo();" > button><br/>
<button onclick="setTimeoutDemo();" > button><br/>
<button onclick="clearTimeoutDemo();" > button><br/>
<button onclick="setIntervalDemo();" > 2button><br/>
<button onclick="clearIntervalDemo();" > 2button><br/>
body>
<script type="text/javascript">
//
function alertDemo(){
alert(" ");
}
//
function confirmDemo(){
var cf = confirm(" ?");
alert(" , true, , false; :"+cf);
}
//
function promptDemo(){
var name = prompt(" :");
alert(" :"+name);
}
//
function openDemo(){
open("JSDemo1.html");
}
// ,
var setTimeoutName ;
var i = 0;
var setTimeoutDemo = function(){
alert(" :"+(++i)+" ");
setTimeoutName = setTimeout(setTimeoutDemo,2000);
}
//
function clearTimeoutDemo(){
clearTimeout(setTimeoutName);
i = 0;
alert(" ");
}
// ,
function setIntervalDemo(){
setTimeoutName = setInterval(function(){
alert(" :"+(++i)+" ");
},2000);
}
//
var clearIntervalDemo = function(){
clearInterval(setTimeoutName);
i = 0;
alert(" ");
}
script>
html>
정시 퀘 스 트 데모
<html>
<head>
<meta charset="UTF-8">
<title> DEMOtitle>
head>
<body>
, <span id="timer">5span> , , <a href="JSDemo1.html"> a> 。
body>
<script type="text/javascript">
// , , 1 , ,
var time = 4;
//
var name = setInterval(
function(){
// id timer
var timer = document.getElementById("timer");
// 0
if(time > 0){
//
timer.innerHTML = time-- ;
}else{
//
clearInterval(name);
//
location.href="JSDemo1.html";
}
} ,
//
1000
);
script>
html>