Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我想在单击按钮时生成布尔值_Javascript_Php_Html - Fatal编程技术网

Javascript 我想在单击按钮时生成布尔值

Javascript 我想在单击按钮时生成布尔值,javascript,php,html,Javascript,Php,Html,我只想在用户确认后执行一些脚本。 if 'confirm' is clicked, then $confirm = true; if($confirm) { some script } else { other script } ?> 像这样的示例代码 if 'confirm' is clicked, then $confirm = true; if($confirm) { some script } else { other s

我只想在用户确认后执行一些脚本。
if 'confirm' is clicked, then $confirm = true;   

if($confirm)
 {
   some script
 }
else
 {
   other script
 }
 ?>
像这样的示例代码
if 'confirm' is clicked, then $confirm = true;   

if($confirm)
 {
   some script
 }
else
 {
   other script
 }
 ?>

有两个按钮“确认”和“放弃”。如果单击确认,则$confirm=true

假设你有两个这样的按钮

<input type="button" name="confirm" id="confirm" value="confirm">
<input type="button" name="discard" id="discard" value="discard">
$(document).ready(function() {
   $("#confirm").on('click',function(){
     alert('Confirm clicked');
     //If you need to communicate with the server the do an ajax call here
   });

   $("#discard").on('click',function(){
     alert('Discard clicked');
     //If you need to communicate with the server the do an ajax call here
   });
});

如果使用javascript,则可以从

中检查单击事件引用,然后使用以下命令:-

if(window.confirm("please confirm"))
{
    return true;
    // or do Your operation.
}
else{
    return false;
    // or do Your operation.
}

否则,您可以使用jquery。

您可以使用php,使用环境php变量提取字段的状态,您只需制作一个公式并将一些数据发送到您的Web服务器脚本文件

<?php
$confirm = $_POST["name_of_the_button"]
if(isset($confirm))
 {
   some script
 }
else
 {
   other script
 }

$(文档).ready(函数(){
$(“输入:按钮”)。在('click',function()上{
如果($(this.id='confirm'){
//把你的剧本放在这里
}否则{
//把你的脚本放在这里}
});
});

您必须使用javascript或jquery来检查
confirm()
在javascript或jquery对话框或类似的东西中,您不能将php代码放在客户端机器上,它只能放在您的服务器上。因此,您需要进行AJAX调用,将用户单击的选项(true/false)发送到服务器,然后将响应发送回客户机,或者在客户机上使用javascript。然后您需要使用AJAX,点击按钮进行AJAX调用。然后在php中,您将检查调用该脚本的按钮的id。如果没有找到,我将发布一个解决方案。更新了我的帖子。
<?php
$action = $_POST["id"];
$confirm = false;
if($action=="confirmed")
    $confirm = true;
else if($action=="declined")
    $confirm = false;
else {}
?>
<input type="button" name="confirm" id="confirm" value="confirm"> 
<input type="button" name="discard" id="discard" value="discard">

$(document).ready(function() {    
  $("input:button").on('click',function(){
    if($(this).id == 'confirm'){ 
      // put your script here
    }else{ 
      // put your script here }   
    });

});