简体   繁体   English

PHP函数点击运行

[英]PHP function run on click

Im trying to run a php function on click as showed below but it just returns a 500 error ive tried this 我试图在单击上运行一个php函数,如下所示,但它只返回500错误。

function doakrim(){
    echo "Test";
}
while (list($key, $val) = each($handlinger))
{
   echo '<tr onclick="document.write('<?php doakrim(); ?>');"><td>'. $val .'</td><td>TEXT</td></tr>';
}

but that just return a 500 error on my webpage any clue what im doing wrong? 但这只是在我的网页上返回500错误,提示我做错了什么? i would love some help here. 我希望在这里有所帮助。

You can't run a PHP function from within the javascript, however its possible to inject the value you need within your javascript's .write method. 您无法从javascript内部运行PHP函数,但是可以在javascript的.write方法中注入所需的值。

I cant see a happy ending for the provided example above:) maybe it's best to first clarify what is exactly the problem? 对于上面提供的示例,我看不到圆满的结局:)也许最好先弄清楚到底是什么问题?

But if you have to make it functional here is a slightly cleaner approach 但是,如果您必须使其功能正常,那是一种稍微清洁的方法

function doakrim()
{
    return "Test";
}

while (list($key, $val) = each($handlinger)) {
    echo '<tr onclick="document.write(\''. doakrim() .'\');"><td>'. $val .'</td><td>TEXT</td></tr>';
}

there is chance what you really need is an Ajax call to fetch the doakrim result back from a server, but its hard to say before knowing what exactly you want to achieve :) 您真正需要的是一个Ajax调用,以从服务器取回doakrim结果,但是在知道您到底想要实现什么之前很难说:)

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

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