【发布时间】:2015-01-11 07:14:53
【问题描述】:
当一个 Javascript 函数被调用 - show_picture() - 从 sprintf() 时,它可以正常工作(代码如下):
$user_row = sprintf("<a href='javascript:show_picture(%d);'> " .
"<img src='images/missing_user.png' width='15' /></a> ", $user['user_id']);
当一个 php 函数被调用 - show_user_func() - 从 sprintf() 它不起作用。错误信息是:
The requested URL /show_user_func(168); was not found on this server.
代码是:
sprintf("<a href='show_user_func(%d);'>%s %s</a> ",
$user['user_id'], $user['first_name'], $user['last_name']);
对此可能有一个简单的解释,但目前我无法理解。有人有什么想法吗?
【问题讨论】:
-
您不能从 HTML 链接调用 PHP 函数,除非您使用该链接请求另一个页面,并且该页面运行 PHP 函数。
-
感谢亚历山大。当我实现下面给出的解决方案时,无需等待单击链接即可调用该函数。所以看来你是对的。
标签: php