[英]How to put prompt alert and confirm together?
如何將提示,警報和確認放在一起? 我已經知道了,但是我想在提示和警告之后添加一個確認框。.有人可以幫忙嗎?
<script>
var name = prompt('What is your name?')
alert('Your name is ' + name )
正如Patrick在評論中建議的那樣,您需要使用Confirm而不是Alert,單擊Confirm OK將為您提供值:true即
<script>
var name = prompt('What is your name?');
var confirm = confirm('Your name is ' + name );
if(confirm === true){
//Your code goes here
}
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var name = prompt("Please enter your name", "XYZ");
if (name != null) {
alert('Your name is ' + name )
}
}
</script>
</body>
</html>
它會詢問您的名字,並在給出提示后提示您。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.