Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.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
Php 添加一个javascript变量并随post一起发送_Php_Javascript_Html - Fatal编程技术网

Php 添加一个javascript变量并随post一起发送

Php 添加一个javascript变量并随post一起发送,php,javascript,html,Php,Javascript,Html,我有这个密码: $image_action = $_POST['image_action']; echo ' <form action="" method=post onmousedown="rightbutton(event)"> <input type="image" src="image.jpeg" style="cursor:crosshair" /> </form&g

我有这个密码:

$image_action = $_POST['image_action'];   
echo '  
<form action="" method=post onmousedown="rightbutton(event)">
<input type="image"  
            src="image.jpeg"  
            style="cursor:crosshair"  />   
        </form>      '; 

<script type="text/javascript">
function rightbutton(event)
{
    if(event.button==2) {  document.getElementById("click").innerHTML="Last action: Right Click";  }
    else{
        if(event.button==0) {  document.getElementById("click").innerHTML="Last action: Left Click";  }  
        else {
            if(event.button==1) {  document.getElementById("click").innerHTML="Last action: Middle Click";  }
        }
    }

}
</script>

但是我得到了一个错误:
未定义索引:key

如果通过console.log()函数调试隐藏元素会发生什么?除了Samuel的评论之外,我还建议将值设置为event.button值,而不仅仅是event,它不能通过post变量传递……嗯,我有“form.setAttribute(“method”,method”);”方法后=方法| |“post”;而且没有任何变化:(我还更改了“hiddenField.setAttribute(“value”,event.button)”
method = method || "post";
var hiddenField = document.createElement("input");
    hiddenField.setAttribute("type", "hidden");
    hiddenField.setAttribute("name", image_action);
    hiddenField.setAttribute("value", event);
form.appendChild(hiddenField);
document.body.appendChild(form);
form.submit();