简体   繁体   English

使用PHP的InnerHTML

[英]InnerHTML with PHP

I'm trying to run php function inside javascript and pass a parameter to that function but with no luck. 我正在尝试在javascript中运行php函数并将参数传递给该函数但没有运气。

here's my code: 这是我的代码:

var attribute = 1;
var element = getElementByID('wrapper').innerHTML="<?php echo myfunction("+attribute+");?>";

But the result I'm getting is the output of my function with "+attribute+" added to it, not the proper output of the function. 但我得到的结果是我的函数的输出添加了“+ attribute +”,而不是函数的正确输出。

The function itself is an easy one: 功能本身很简单:

<?php myfunction($attribute){
    echo 7+$attribute;
}?>

Php would be executed by the server, but the server isn't involved anymore once your client has started processing javascript. Php将由服务器执行,但是一旦您的客户端开始处理javascript,服务器就不再涉及了。 So no, I don't think this is possible. 所以不,我不认为这是可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM