dqitk20644
2018-05-15 04:19
浏览 526
已采纳

单击按钮后如何显示弹出确认

I'm still a learner on PHP.

I have a button, and it shall run a JavaScript after clicking it, but I want it to show an alert / pop up for users to confirm whether to continue or to abort.

Can I do the function in my PHP file in the button code?

<TD style='text-align:left;padding:0;margin:0;'>
    <INPUT type='button' onmouseup="javascript:JS1();" value='JS1'></INPUT>
</TD>

图片转代码服务由CSDN问答提供 功能建议

我仍然是PHP的学习者。

我有一个按钮 ,点击它后它将运行一个JavaScript,但我希望它显示一个警告/弹出窗口,供用户确认是继续还是中止。

我可以执行此功能吗? 我的PHP文件在按钮代码中?

 &lt; TD style ='text-align:left; padding:0; margin:0;'&gt; 
&lt; INPUT  type ='button'onmouseup =“javascript:JS1();”  value ='JS1'&gt;&lt; / INPUT&gt; 
&lt; / TD&gt; 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dpp3047 2018-05-15 04:23
    已采纳

    you need to make function and use confirm();

    <TD style='text-align:left;padding:0;margin:0;'>
                <INPUT type='button' onmouseup="myFunction();" value='JS1'></INPUT>
            </TD>
    

    And

    <script>
    function myFunction() {
        confirm("Please confrim");
    }
    </script>
    
    点赞 评论
  • doushang1778 2018-05-15 04:24

    Have you tried bootstrap modal?

    https://www.w3schools.com/bootstrap/bootstrap_modal.asp

    https://getbootstrap.com/docs/4.0/components/modal/

    https://getbootstrap.com/docs/3.3/javascript/

    I have provided 3 links. I think these might help you a little. Do a research and it won't be very hard. Good luck.

    点赞 评论
  • duanqiongchong0354 2018-05-15 04:25

    Writing code is not what is supposed here.

    But, still following pseudo code and concepts should work.

    Steps:

    1. If you are using jQuery, bind the event of click. If you are using core Javscript, use onclick attribute.
    2. In the onclick function, add a confirmation popup.
    3. confirm() returns true if user selects yes, or else it will return false.
    4. Now, you have to proceed only if true is returned by confirm().

    And javascript code:

    <script>
    function JS1() {
     if (confirm('Your confirmation message')) {
      // Write your code of form submit/button click handler.
     }
     else {
      return false;
     }
    }
    </script>
    
    点赞 评论

相关推荐 更多相似问题