【问题标题】:How to put prompt alert and confirm together?如何将提示警报和确认放在一起?
【发布时间】:2017-03-04 11:04:16
【问题描述】:

如何将提示、警告和确认放在一起? 我已经得到了这个,但我想在提示和警报之后添加一个确认框.. 有人可以帮忙吗?

<script>

var name = prompt('What is your name?')

alert('Your name is ' + name )

【问题讨论】:

  • 顺便说一句:我想要一个带有名字的确认框。
  • 然后执行与 alert() 相同的操作,但将 alert 替换为 confirm。如果您要问如何将它们全部制作成一个框,则不能,至少不能使用本机对话框
  • How to put prompt alert and confirm together? - 我同意他们属于一起,但绝不会出现在面向公众的网页中:p

标签: javascript prompt


【解决方案1】:

正如 Patrick 在 cmets 中建议的那样,您需要使用 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
}

【讨论】:

    【解决方案2】:
    <!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>
    

    它会询问你的名字,并在给出名字提示后发出警报。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-05
      • 2023-03-15
      • 2016-03-15
      相关资源
      最近更新 更多