如何在按钮onclick中设置javaScript和php代码? [英] How to set javaScript and php code in button onclick ?

查看:261
本文介绍了如何在按钮onclick中设置javaScript和php代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做这样的儿子!我怎么做?

Hi i want do sonmthing like this ! How i can do it ?

<button style="width:250px;" id="enable_voiceChat" >">sent accept message</button>
<script>
function domessage()
{
//do some javaScript ...
}
</script>

推荐答案

因为你的javascript代码在客户端运行而你的php代码在服务器端运行,这两个是不能同时运行,你不能在客户端运行php代码。你可以做的是从客户端到服务器端进行调用来做一些事情。您有两种选择:要么发布表单并刷新整个页面,要么使用ajax后台调用调用ajax后端。这种后来的方法现在更常见。我建议你参考这个教程: http://blog.teamtreehouse.com/beginners-guide -to-ajax-development-with-php [ ^ ]
As your javascript code runs on client side and your php code runs on server side, and these two are not running at same time, you can not run php code on client side. What you can do is making a call from the client side to the server side to do some stuff. You have two choices: either you post a form and refresh the whole page, or you call an ajax backend with an ajax background call. This later approach is more common nowadays. I suggest you consult this tutorial: http://blog.teamtreehouse.com/beginners-guide-to-ajax-development-with-php[^]


这篇关于如何在按钮onclick中设置javaScript和php代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆