从PHP调用jQuery函数
如何从PHP调用jQuery函数?
error('1');
它不起作用。
不,你不能从PHP调用jQuery函数。 但是您可以使用PHP生成html,它将在运行时执行jQuery函数。
- Javascript被发送到客户端并在那里执行
- PHP在服务器上编译,然后发送到客户端
差别很大
脚本标签不能直接注入php标签….但如果你回应它,脚本将工作….以下代码工作:
alert('Hello World');"; } ?>
在使用jQuery的情况下,您必须将代码包装在:
jQuery(function(){ //Your Code });
然后回应它….
这取决于您将此代码片段放在HTML输出中的位置。
我认为其中一个解决方案应该有效:
} ?> } ?>
您需要指定error('1')
是对jQuery函数的调用:
jQuery.error('1'); // or, uning the $ alias: $.error('1');
?>
或者使用jquery $ .ajax来调用PHP函数