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>

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


我有一个按钮 ,点击它后它将运行一个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>


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

    Have you tried bootstrap modal?




    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.


    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:

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

相关推荐 更多相似问题