[英]not alerting the variable value passed from onclick php function
on click, a)I am not getting alert, when i pass $picname variable to jquery img function(the value of the $picname is tulips.jpg) 在单击时,a)当我将$ picname变量传递给jquery img函数时,我没有收到警告($ picname的值是Tulips.jpg)
b)i am getting the alert (22) when i pass the variable $picid(the value of the $picid is 22) b)当我传递变量$ picid($ picid的值为22)时,我收到警报(22)
i think jquery function does not alert images extentions,if so then how can i pass the image name variable whose value having extension,to the jquery function to use its value 我认为jquery函数不会警告图像扩展,如果是的话,如何将具有扩展名的图像名称变量传递给jquery函数以使用其值
function profile(){
$sql = mysql_query("SELECT * FROM profile");
while ($row = mysql_fetch_array($sql)) {
$picname= $row['picname'];
$picid= $row['id'];
?>
<table style="margin-left: 110px">
<tr><td><a href="#img" class="ok"><img style='width: 200px' src="images/<?php echo $picname ?>" alt="name" onclick=img(<?php echo $picname ?>); ></a></td></tr>
</table>
<?php
}}
jquery function is jQuery函数是
function img(n){
alert(n);
}
You need to use the single quote for JS strings and it wouldn't also be bad to use a double quote to wrap the value of the onclick
attribute 您需要对JS字符串使用单引号,并且使用双引号来包装onclick
属性的值也不错
onclick="img('<?php echo $picname ?>')"
^ ^
here is the problem 这是问题
<a href="#img" class="ok"><img style='width: 200px' src="images/<?php echo $picname ?>" alt="name" onclick=img(<?php echo $picname ?>); ></a>
should be 应该
<a href="#img" class="ok"><img style='width: 200px' src="images/<?php echo $picname ?>" alt="name" onclick="img('<?php echo $picname ?>')" ></a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.