ล่าสุดการพัฒนาเว็บบทเรียน
×

JavaScript การอ้างอิง

ภาพรวม

JavaScript

JS เชือก JS จำนวน JS ผู้ประกอบการ JS งบ JS คณิตศาสตร์ JS วันที่ JS แถว JS บูลีน JS นิพจน์ทั่วไป JS สถานการณ์โดยรวม JS การแปลง

เบราว์เซอร์ BOM

Window Navigator Screen History Location

HTML DOM

DOM เอกสาร DOM องค์ประกอบ DOM แอตทริบิวต์ DOM เหตุการณ์ DOM รูปแบบ

HTML วัตถุ

<a> <abbr> <address> <area> <article> <aside> <audio> <b> <base> <bdo> <blockquote> <body> <br> <button> <canvas> <caption> <cite> <code> <col> <colgroup> <datalist> <dd> <del> <details> <dfn> <dialog> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <footer> <form> <head> <header> <h1> - <h6> <hr> <html> <i> <iframe> <img> <ins> <input> button <input> checkbox <input> color <input> date <input> datetime <input> datetime-local <input> email <input> file <input> hidden <input> image <input> month <input> number <input> password <input> radio <input> range <input> reset <input> search <input> submit <input> text <input> time <input> url <input> week <kbd> <keygen> <label> <legend> <li> <link> <map> <mark> <menu> <menuitem> <meta> <meter> <nav> <object> <ol> <optgroup> <option> <output> <p> <param> <pre> <progress> <q> <s> <samp> <script> <section> <select> <small> <source> <span> <strong> <style> <sub> <summary> <sup> <table> <td> <th> <tr> <textarea> <time> <title> <track> <u> <ul> <var> <video>

วัตถุอื่น ๆ

CSSStyleDeclaration


 

JavaScriptทำ / ขณะที่คำสั่ง

งบ JavaScript อ้างอิง งบ JavaScript อ้างอิง

ตัวอย่าง

วงนี้จะถูกดำเนินการอย่างน้อยหนึ่งครั้งแม้ถ้าเงื่อนไขเป็นเท็จเพราะการป้องกันรหัสจะถูกดำเนินการก่อนที่จะอยู่ในสภาพที่มีการทดสอบ:

var text = "";
var i = 0;
do {
    text += "The number is " + i;
    i++;
}
while (i < 5);

ผลของข้อความที่จะได้รับ:

The number is 0
The number is 1
The number is 2
The number is 3
The number is 4
ลองตัวเอง»

ความหมายและการใช้งาน

ทำ / ขณะที่คำสั่งสร้างห่วงที่รันบล็อกของรหัสครั้งก่อนการตรวจสอบถ้าเงื่อนไขเป็นจริงแล้วมันจะทำซ้ำห่วงตราบใดที่เงื่อนไขเป็นจริง

ทำ / ขณะที่คำสั่งจะใช้เมื่อคุณต้องการเรียกใช้ห่วงอย่างน้อยหนึ่งครั้งไม่ว่าสิ่งที่

JavaScript สนับสนุนชนิดที่แตกต่างกันของลูป:

  • สำหรับ - loops ผ่านบล็อกของรหัสจำนวนครั้ง
  • สำหรับ / ใน - loops ผ่านคุณสมบัติของวัตถุ
  • ในขณะที่ - loops ผ่านบล็อกของรหัสในขณะที่เงื่อนไขที่ระบุเป็นความจริง
  • ทำ / ขณะที่ - loops ผ่านบล็อกของรหัสครั้งเดียวแล้วซ้ำห่วงในขณะที่เงื่อนไขที่ระบุเป็นความจริง

สนับสนุนเบราว์เซอร์

ตัวเลขในตารางระบุราว์เซอร์รุ่นแรกที่รองรับคำสั่ง

คำแถลง
do/while ใช่ 6.0 ใช่ ใช่ ใช่

วากยสัมพันธ์

do {
    code block to be executed
}
while ( condition );

ค่าพารามิเตอร์

Parameter Description
condition Required. Defines the condition for running the loop (the code block). If it returns true, the loop will start over again, if it returns false, the loop will end.

Note: If the condition is always true, the loop will never end. This will crash your browser.

Note: If you are using a variable with the condition, initialize it before the loop, and increment it within the loop. If you forget to increase the variable, the loop will never end. This will also crash your browser.

รายละเอียดทางเทคนิค

JavaScript เวอร์ชัน: 1.2

หน้าเว็บที่เกี่ยวข้อง

JavaScript Tutorial: JavaScript ในขณะที่ห่วง

JavaScript อ้างอิง: JavaScript ขณะที่คำสั่ง

อ้างอิง javascript: JavaScript สำหรับงบ


งบ JavaScript อ้างอิง งบ JavaScript อ้างอิง