Window prompt()
ဥပမာ ၁
အသုံးပြုသူအမည်အတွက် အချက်ပြပြီး မက်ဆေ့ချ်တစ်ခုထုတ်ပေးပါ-
let person = prompt("Please enter your name", "Harry Potter");
if (person != null) {
document.getElementById("demo").innerHTML =
"Hello " + person + "! How are you today?";
}
အောက်တွင် နောက်ထပ် ဥပမာများ။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
နည်းလမ်း သည် prompt()
အသုံးပြုသူကို ထည့်သွင်းရန်အတွက် အချက်ပြသည့် dialog box ကို ပြသသည်။
အသုံးပြုသူ က prompt()
"OK" ကိုနှိပ်ပါက၊ သို့မဟုတ်ပါက ၎င်းသည် ထည့်သွင်းမှုတန်ဖိုးကို ပြန်ပေးသည် null
။
မှတ်ချက်
အသုံးပြုသူကို တန်ဖိုးတစ်ခုထည့်သွင်းလိုပါက prompt box ကိုအသုံးပြုသည်။
prompt box ပေါ်လာသောအခါ၊ အသုံးပြုသူသည် ဆက်လက်ဆောင်ရွက်ရန် "OK" သို့မဟုတ် "Cancel" ကိုနှိပ်ရပါမည်။
ဒီနည်းလမ်းကို အလွန်အကျွံမသုံးပါနဲ့။ ၎င်းသည် ဘောက်စ်မပိတ်မချင်း စာမျက်နှာ၏ အခြားအစိတ်အပိုင်းများကို အသုံးပြုသူကို ဝင်ရောက်ခြင်းမှ တားဆီးပေးသည်။
ကိုလည်းကြည့်ပါ-
အထားအသို
prompt(text, defaultText)
ကန့်သတ်ချက်များ
Parameter | Description |
text | Required. The text to display in the dialog box. |
defaultText | Optional. The default input text. |
တန်ဖိုးကို ပြန်ပေးသည်။
ကန့်သတ်ချက် | ဖော်ပြချက် |
ကြိုးတစ်ချောင်း |
အသုံးပြုသူက "OK" ကိုနှိပ်ပါက input value ကိုပြန်ပေးပါသည်။ မဟုတ်ရင် ပြန်လာမယ် null ။ |
နောက်ထပ် ဥပမာများ
သူ့အကြိုက် သောက်စရာကို နှိုးဆော်ပါ။
let text;
let favDrink = prompt("What's your favorite cocktail drink?");
switch(favDrink) {
case "Coca-Cola":
text = "Excellent choice! Coca-Cola is good for your soul.";
break;
case "Pepsi":
text = "Pepsi is my favorite too!";
break;
case "Sprite":
text = "Really? Are you sure the Sprite is your favorite?";
break;
default:
text = "I have never heard of that one!";
}
Browser ပံ့ပိုးမှု
prompt()
ဘရောက်ဆာအားလုံးတွင် ထောက်ခံသည်-
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |