Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
331 views
in Technique[技术] by (71.8m points)

javascript - 如何使用“是”和“否”选项创建对话框?(How to create a dialog with “yes” and “no” options?)

I am going to make a button to take an action and save the data into a database.

(我将创建一个按钮来执行操作并将数据保存到数据库中。)

Once the user clicks on the button, I want a JavaScript alert to offer “yes” and “cancel” options.

(一旦用户点击按钮,我想要一个JavaScript提醒,提供“是”和“取消”选项。)

If the user selects “yes”, the data will be inserted into the database, otherwise no action will be taken.

(如果用户选择“是”,则数据将被插入数据库,否则将不执行任何操作。)

How do I display such a dialog?

(如何显示这样的对话框?)

  ask by crchin translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You're probably looking for confirm() , which displays a prompt and returns true or false based on what the user decided:

(您可能正在寻找confirm() ,它会显示提示并根据用户决定的内容返回truefalse :)

if (confirm('Are you sure you want to save this thing into the database?')) {
    // Save it!
} else {
    // Do nothing!
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...