javascript函数被调用时从PHP参数 [英] javascript function not get called when arguments from php
本文介绍了javascript函数被调用时从PHP参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在运行的<一>在PHP标签。每当我通过在js函数的参数就不会被调用,但如果我通过空参数,函数被调用。
I am running the < a > tag in php. Whenever I pass an argument in js function it does not get called but if i pass empty arguments, the function gets called.
JS:
function displayBigImage(img){
alert("inside func");
}
PHP:
//NOT WORKING:
echo "<a href='javascript:displayBigImage('".$row['IMG_ID']."')'>Press</a>";
//WORKING:
echo "<a href='javascript:displayBigImage()'>Press</a>";
我也试图与哈日code参数值一样,
I also tried with harcode argument values like,
echo "<a href='javascript:displayBigImage('sample.jpg')'>Press</a>";
或
echo "<a href='javascript:displayBigImage(sample.jpg)'>Press</a>";
我不明白什么是错?!?!?!?!
I don't understand whats wrong?!?!?!?!
请尽快答复
在此先感谢
推荐答案
您与您的报价问题:
<a href='javascript:displayBigImage('sample.jpg')'>
您不能使用的的HTML属性和在的这单引号都的左右。你需要在两个地方使用不同的报价,例如:
You can't use single quotes both around the HTML attribute and within it. You need to use different quotes in the two places, for instance:
<a href="javascript:displayBigImage('sample.jpg')">
所以,在你的PHP,即变为:
So in your PHP, that becomes:
echo "<a href=\"javascript:displayBigImage('".$row['IMG_ID']."')\">Press</a>";
这篇关于javascript函数被调用时从PHP参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文