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

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


 

หน้าต่าง prompt() Method

<หน้าต่างวัตถุ

ตัวอย่าง

แสดงกล่องพรอมต์ซึ่งขอให้ผู้ใช้สำหรับเธอชื่อ / ของเขาและเอาท์พุทข้อความ:

var person = prompt("Please enter your name", "Harry Potter");

if (person != null) {
    document.getElementById("demo").innerHTML =
    "Hello " + person + "! How are you today?";
}
ลองตัวเอง»

เพิ่มเติม "Try it Yourself" ตัวอย่างด้านล่าง


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

prompt() วิธีการแสดงกล่องโต้ตอบที่แจ้งให้ผู้เข้าชมสำหรับการป้อนข้อมูล

กล่องพรอมต์มักจะใช้ถ้าคุณต้องการให้ผู้ใช้ป้อนค่าก่อนที่จะเข้าหน้า

หมายเหตุ: เมื่อกล่องพร้อมท์ปรากฏขึ้นผู้ใช้จะต้องคลิก "OK" หรือ "Cancel" เพื่อดำเนินการต่อหลังจากที่ป้อนค่าการป้อนข้อมูล อย่ามากเกินไปวิธีนี้มันป้องกันผู้ใช้จากการเข้าถึงส่วนอื่น ๆ ของหน้าจนกว่ากล่องปิด

prompt() วิธีการส่งกลับค่าการป้อนข้อมูลหากผู้ใช้คลิก "OK" หากผู้ใช้คลิก "cancel" วิธีการส่งกลับ null


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

วิธี
prompt() ใช่ ใช่ ใช่ ใช่ ใช่

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

prompt( ค่าพารามิเตอร์
พารามิเตอร์ ชนิด ลักษณะ
text String จำเป็นต้องใช้ ข้อความที่จะแสดงในกล่องโต้ตอบ
defaultText String ไม่จำเป็น. ข้อความที่ป้อนข้อมูลเริ่มต้น

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

กลับค่า: สตริง. หากผู้ใช้คลิก "OK" ค่าการป้อนข้อมูลจะถูกส่งกลับ หากผู้ใช้คลิก "cancel" , null จะถูกส่งกลับ หากผู้ใช้คลิกตกลงโดยไม่ต้องป้อนข้อความใด ๆ สตริงที่ว่างเปล่าจะถูกส่งกลับ

ตัวอย่าง

ตัวอย่างอื่น ๆ

ตัวอย่าง

การใช้คำสั่งสวิทช์ร่วมกับ prompt() ในการดำเนินการบล็อกของรหัสบนพื้นฐานของข้อมูลของผู้ใช้:

var text;
var favDrink = prompt("What's your favorite cocktail drink?");
switch(favDrink) {
    case "Martini":
        text = "Excellent choice! Martini is good for your soul.";
        break;
    case "Daiquiri":
        text = "Daiquiri is my favorite too!";
        break;
    case "Cosmopolitan":
        text = "Really? Are you sure the Cosmopolitan is your favorite?";
        break;
    default:
        text = "I have never heard of that one..";
        break;
}
ลองตัวเอง»

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

วัตถุหน้าต่าง: href="met_win_alert.html"> alert() Method

วัตถุหน้าต่าง: href="met_win_confirm.html"> confirm() Method


<หน้าต่างวัตถุ