来自php的参数时不会调用javascript函数 [英] javascript function not get called when arguments from php

查看:27
本文介绍了来自php的参数时不会调用javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 <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>";

我也尝试过使用硬编码参数值,例如,

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>";

这篇关于来自php的参数时不会调用javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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