单击使用php提交的html表单后弹出窗口

时间:2017-08-24 08:42:35

标签: javascript php html popup

我有一个提交按钮"证书副本"当我点击按钮时,它应该显示一个弹出窗口。 下面是我的HTML代码。

print "<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'></script>";
print "<form action='details.php' name='copy' method='POST' target='_blank'>";


        print "<input type='hidden' name='certificate_name' value='$certificate_name'>";
        print "<input type='hidden' name='certificate_id' value='$certificate_id'>";


        print "<input type='submit' name='certificatecopy' id='certificate' value='Certificate Copy'>";

print "</form>" ;

我的弹出代码是

    print "<script> $(document).on('click','#certificate',function(){val = confirm('Do you want to create a new certificate?');
alert(val);
if(val)
{
     alert('proceed '); 
     return true;
}
else
{
   alert('Dont proceed');
   return false;
}
});</script>";

我的问题是,当我第一次点击按钮时,弹出框不会出现。但是当第二次点击按钮时,会出现弹出框。问题是什么。第一次点击按钮时我需要弹出窗口。请帮忙。

3 个答案:

答案 0 :(得分:0)

您需要在按钮点击事件的客户端执行此操作。

确认将返回布尔值true或false。根据用户点击。

&#13;
&#13;
$(document).on('click','#certificate',function(){

val = confirm('This will create a new certificate with all properties and links from the original certificate. A certificate user may edit the new certificate properties, but may not delete the certificate. Do you want to create a new certificate?');

alert(val);

if(val)
{
     alert('proceed '); 
     return true;
}
else
{
   alert('Dont proceed');
   return false;
}
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action='details.php' name='copy' method='POST' target='_blank'>

 <input type='hidden' name='certificate_name' value='$certificate_name'>
  
  <input type='hidden' name='certificate_id' value='$certificate_id'>


<input type='submit' name='certificatecopy' id="certificate" value='Certificate Copy'>
</form>
&#13;
&#13;
&#13;

更新1:

<?php
print "<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'></script>";
print "<form action='details.php' name='copy' method='POST' target='_blank'>";


        print "<input type='hidden' name='certificate_name' value='$certificate_name'>";
        print "<input type='hidden' name='certificate_id' value='$certificate_id'>";


        print "<input type='submit' name='certificatecopy' id='certificate' value='Certificate Copy'>";

print "</form>" ;

print "<script> $(document).on('click','#certificate',function(){val = confirm('Do you want to create a new certificate?');
alert(val);
if(val)
{
     alert('proceed '); 
     return true;
}
else
{
   alert('Dont proceed');
   return false;
}
});</script>";

?>

答案 1 :(得分:0)

而不仅仅在$_SESSION['pop_up']中添加echo

if(isset($_POST['certificatecopy'])){

  echo "<script>
            .....................
            .....................
        </script>";

答案 2 :(得分:0)

您想在向服务器发送请求之前要求确认客户端吗?

如果您使用Bootstrap,您可以尝试我制作的一个小jQuery插件https://github.com/delboy1978uk/bs-delete-confirm。它不需要仅用于删除,它只是命名,因为它是最常用的案例。

您只需在链接中添加CSS类:

<a href="/wherever" class="confirm">Do stuff!</a>

和javascript:

$(document).ready(function(){
  $('.confirm').deleteConfirm();
});

现在,当您单击该链接时,JS会拦截它,启动一个引导模式窗口,并在确认后,跟随您的超链接。

您也可以将选项传递给deleteConfirm()方法:

{
  heading: "Please confirm",
  body: "Are you sure you wish to perform this action?",
  ok_text: "Proceed",
  cancel_text: "Back",
  log: false
}

希望这有帮助!如果您不使用Bootstrap,那么值得添加到您的项目中!这是指向模态功能的链接: https://getbootstrap.com/docs/3.3/javascript/#modals