如何将php变量作为参数传递给JavaScript函数 [英] How to pass php variable to JavaScript function as parameter

查看:77
本文介绍了如何将php变量作为参数传递给JavaScript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将php图像网址作为javascript函数参数传递.

I want to pass php image url as javascript function parameter.

请让我知道我该怎么做.

Please let me know how can I do this.

<html> 
<?php
$image=$row['image'];
$img=$loc.'user/'.$image;
?>

<script type=text/javascript>
function demo()
{
some code here;
}
   </script>

<body>
<button type="submit" onclick=demo(<?php echo $img?>) >
</body>
</html>

在javascript中,我正在对image进行一些编辑工作.

In javascript I am doing some editing work on image .

如何传递此php变量(即图片网址作为javascript函数参数)

How can I pass this php variable (i.e. image url as javascript function parameter)

推荐答案

您必须将其用引号引起来,并且必须关闭button

You have to wrap it with quotes and you have to close the button

<button type="submit" onclick='demo("<?php echo $imageurl?>")' ></button>

这篇关于如何将php变量作为参数传递给JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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