如何将php变量作为参数传递给JavaScript函数
我想将php image url作为javascript函数参数传递。
请让我知道我该怎么做。
function demo() { some code here; } <button type="submit" onclick=demo() >
在javascript中,我正在对图像进行一些编辑工作。
我怎样才能传递这个php变量(即图像url作为javascript函数参数)
您需要将PHP代码quotes
在quotes
如as
在您的Javascript中,因为您在函数内传递值但未在function demo()
捕获该值
function demo(obj) { //^^^ Capturing value within function using variable name obj alert(obj); }
你必须用引号包装它,你必须关闭button
我发现$img
是你的变量,在代码中你试图发送$imageurl