Window prompt() 方法
- ຫນ້າກ່ອນ print()
- ຫນ້າຕໍ່ໄປ resizeBy()
- ກັບຄືນອັບສັດສູງສຸດ Window Object
Definition and usage
prompt()
The method displays a dialog box prompting the user to enter.
If the user clicks "OK", then prompt()
The method returns the input value, otherwise returns null
.
Note
If you want the user to enter a value, use the prompt box.
When the pop-up prompt box appears, the user must click "OK" or "Cancel" to continue.
Do not overuse this method. It will block the user from accessing other parts of the page before closing the box.
See also:
Example
Example 1
Prompt input username and output message:
let person = prompt("Please enter your name", "Harry Potter"); if (person != null) { document.getElementById("demo").innerHTML = "Hello " + person + "! How are you today?"; }
Example 2
Prompt his favorite drink:
let text; let favDrink = prompt("What is your favorite drink?"); switch(favDrink) { case "Coca-Cola": text = "A great choice! Coca-Cola is good for your soul."; break; case "Pepsi": text = "Pepsi is also my favorite!"; break; case "Sprite": text = "Is it true? Are you sure Sprite is your favorite?"; break; default: text = "I have never heard of that!"; }
Syntax
prompt(message, default)
parameter
parameter | ກ່າວ |
---|---|
message | required. Text to be displayed in the dialog. |
default | optional. Default input text. |
ຄູ່ມືກັບຄືນ
ປະເພດ | ກ່າວ |
---|---|
string |
ຖ້າຜູ້ນຳໃຊ້ຄົງຄວາມຕົກລົງ, ຈະກັບຄືນຄູ່ມື. ຖ້າຜູ້ນຳໃຊ້ບໍ່ບັນທຶກຫຍັງຈະກັບຄືນຄວາມຂຽນທີ່ຕົກລົງ. ຖ້າບໍ່ໄດ້ບັນທຶກຫຍັງຈະກັບຄືນ null. |
ກ່າວ
prompt()
ວິທີຈະສະແດງຂອງສະເພາະດັ່ງກ່າວ message, ສະເພາະດັ່ງກ່າວມີບາງບານຄົນຂຽນ, ຄົງຄວາມຕົກລົງ, ຄົງການຍົກເລີກ, ທີ່ຕັ້ງໃຈໂດຍການສະແດງສາຍຂອງພາຍສະພາບການສະແດງຂອງຕະບັດຍິງສະແດງຕໍ່ຜູ້ນຳໃຊ້ວ່າຕ້ອງການບັນທຶກ.
ຖ້າຜູ້ນຳໃຊ້ຄົງການຍົກເລີກprompt()
ວິທີຈະກັບຄືນ null
. ຖ້າຜູ້ນຳໃຊ້ຄົງຄວາມຕົກລົງprompt()
ຈະກັບຄືນຄວາມຂຽນທີ່ປະກົດຢູ່ໃນບາງບານຄົນ.
ຈາກ prompt()
ການສະແດງຂອງສະເພາະດັ່ງກ່າວແມ່ນມີການລະບຸຂອງຕົວເລື່ອງທີ່ມີການກັບກັນຄວາມຄິດເຫັນຂອງຜູ້ນຳໃຊ້ກ່ອນທີ່ຜູ້ນຳໃຊ້ຄົງຄວາມຕົກລົງຫຼືຄົງການຍົກເລີກຕົວເລື່ອງ. ຍ້ອນວ່າຄູ່ມືຂອງວິທີນີ້ກັບຄວາມຄິດເຫັນຂອງຜູ້ນຳໃຊ້, ຖ້າໃຊ້ prompt()
时,将暂停对 JavaScript 代码的执行。在用户做出响应之前,不会执行下一条语句。
ການອອກສາຍບັນດາຄົນທີ່ຈະຮັບການຊ່ວຍເຫຼືອ
ທຸກການອອກສາຍບັນດາຄົນທີ່ຈະຮັບການຊ່ວຍເຫຼືອ prompt()
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
ສະໜັບສະໜູນ | ສະໜັບສະໜູນ | ສະໜັບສະໜູນ | ສະໜັບສະໜູນ | ສະໜັບສະໜູນ | ສະໜັບສະໜູນ |
- ຫນ້າກ່ອນ print()
- ຫນ້າຕໍ່ໄປ resizeBy()
- ກັບຄືນອັບສັດສູງສຸດ Window Object