使用php代码中的参数调用javascript函数


call javascript function with parameters from php code

我想从php调用一个javascript函数并执行ajax调用。我的php代码是:

echo '<script>change2('.$stand.'); </script>';

我的js代码是:

function change2(c){
alert(c);
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","change2.php?c="+c,true);
    xmlhttp.send();
    }

警报返回未定义。。

您可以执行以下操作:<input type="hidden" value="<?php $stand ?>" id="someID">在你的Js

<script>change2(document.getElementByID('someID'); </script>

我认为它起作用了。