提交表单时是否可以将JavaScript变量的内容发送给PHP?
答案 0 :(得分:3)
是。 只需将javascript回调添加到表单提交事件
即可<script type="text/javascript">
var myglobalvariable = "myvalue";
onSubmit = function(){
document.myform.myinput.value = myglobalvariable; return true;
}
</script>
<form name="myform" id="myform" method="post" action="index.php" onsubmit="onSubmit();">
<input name="myinput" id="myinput" type="hidden" />
</form>