通过onclick事件调用php函数 [英] Calling a php function by onclick event
本文介绍了通过onclick事件调用php函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过按钮的onclick事件来调用一个函数。
当我这样做时,它显示错误消息。
任何人都可以帮我解决这个问题,所以当我点击按钮时,它应该调用函数并执行它。
I am trying to call a function by "onclick" event of the button. When I do that it shows error message. Can anybody help me out on this so that when I click on the button it should call the function and execute it.
我的php代码是:
My php code is:
<?php
function hello() {
echo "Hello";
}
echo "<input type='button' name='Release' onclick= hello(); value='Click to Release'>";
?>
这段代码有什么问题?
What is wrong with this code?
推荐答案
首先引用您的javascript:
First quote your javascript:
onclick="hello();"
你也无法从javascript调用php函数;
您需要:
Also you can't call a php function from javascript; you need:
<script type="text/javascript">
function hello()
{
alert ("hello");
}
</script>
这篇关于通过onclick事件调用php函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文