Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.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传递到PHP-弹出/模式窗口 函数showdivv(el、IDV){ var iddd=iddd; var display=document.getElementById(el.style.display); 如果(显示=“无”) document.getElementById(el.style.display='block'; 其他的 document.getElementById(el.style.display='none'; } 所选ID:_Javascript_Php_Html_Variables_Modal Dialog - Fatal编程技术网

将变量从Javascript传递到PHP-弹出/模式窗口 函数showdivv(el、IDV){ var iddd=iddd; var display=document.getElementById(el.style.display); 如果(显示=“无”) document.getElementById(el.style.display='block'; 其他的 document.getElementById(el.style.display='none'; } 所选ID:

将变量从Javascript传递到PHP-弹出/模式窗口 函数showdivv(el、IDV){ var iddd=iddd; var display=document.getElementById(el.style.display); 如果(显示=“无”) document.getElementById(el.style.display='block'; 其他的 document.getElementById(el.style.display='none'; } 所选ID:,javascript,php,html,variables,modal-dialog,Javascript,Php,Html,Variables,Modal Dialog,如果你对重新加载页面没问题,你可以简单的做 <html> <head> <script type="text/javascript"> function showdivv(el, idclicked) { var iddd = idclicked; var display = document.getElementById(el).style.display

如果你对重新加载页面没问题,你可以简单的做

<html>
<head>
        <script type="text/javascript">
            function showdivv(el, idclicked) {
                var iddd = idclicked;
                var display = document.getElementById(el).style.display;
                if(display == "none")
                    document.getElementById(el).style.display = 'block';
                else
                    document.getElementById(el).style.display = 'none';
            }
        </script>
        <?php  $showw = "<script>document.write(iddd)</script>"; ?>
</head>
<body>
    <div id="myDiv" style="display: none;">ID Selected: <?php echo $showw; ?></div>
    <?php $variable = 4; ?>
    <button type="button" onclick="showdivv('myDiv', '<?php echo $variable; ?>')">Show / Hide</button>
</body>
如果不是,我绝对建议使用JQuery,因为它使Ajax查询变得轻而易举

标记内:

window.location.href('php_script_that_needs_your_input.php?id=input_id_from_js');
我在这里使用了示例值,但您可以很容易地使用JavaScript中的变量,如下所示:

function ajax_on_button_press(resultDiv, id) {
   var phpUrl = "php_script.php?id="+id+"&other_variable=cheese&more_info=rats";
   $(resultDiv).load(phpUrl);
}
要启动此过程,您需要一个运行此脚本的按钮。将按钮标记更改为

var other_variable=$('#otherVariableInput').val(); //gets input from a textbox with the html id otherVariableInput
var phpUrl = "php_script.php?id="+id+"&other_variable="+other_variable+"&more_info=rats";

请发布一个可能重复的问题,你能给我发送解决方案吗,用代码?问题是:不要表现出你似乎不理解服务器端代码和客户端代码之间的区别。如果要将变量从javascript传递到php,必须通过html表单或XMLHttprequest(又名ajax)来实现
function ajax_on_button_press(resultDiv, id) {
   var phpUrl = "php_script.php?id="+id+"&other_variable=cheese&more_info=rats";
   $(resultDiv).load(phpUrl);
}
var other_variable=$('#otherVariableInput').val(); //gets input from a textbox with the html id otherVariableInput
var phpUrl = "php_script.php?id="+id+"&other_variable="+other_variable+"&more_info=rats";
<button type="button" onclick="ajax_on_button_press('#phpResult', '<?php echo $variable; ?>')">Show / Hide</button>