Javascript 在php中向输入类型图像添加Click函数,导致未定义错误
我试图从输入类型图像中创建一个Javascript 在php中向输入类型图像添加Click函数,导致未定义错误,javascript,php,Javascript,Php,我试图从输入类型图像中创建一个onClick函数。这是密码 <td> <?php if($ring[ "bandPaths"] !='' ) echo ' <input id="bandImage" type="image" src="http://thevowapp.com/iphoneapp/vowstore/bands/'. $ring[ 'bandPaths'] . '" onClick="openGallery('.$ring[ 'bandPaths']
onClick
函数。这是密码
<td>
<?php if($ring[ "bandPaths"] !='' ) echo '
<input id="bandImage" type="image" src="http://thevowapp.com/iphoneapp/vowstore/bands/'. $ring[ 'bandPaths'] . '" onClick="openGallery('.$ring[ 'bandPaths']. ');" style="width:100px; height:100px; margin-left: 10px;">
'; ?>
</td>
<script>
function openGallery(var url) {
$.colorbox({
width: "80%",
height: "80%",
iframe: true,
href: "/pagetoopen.html"
});
}
</script>
函数openGallery(var url){
$彩色盒({
宽度:“80%”,
身高:“80%”,
伊夫拉姆:是的,
href:“/pagetoopen.html”
});
}
我发现错误
未定义openGallery
。我做错了什么?您的Javascript语法无效,您应该在控制台中遇到语法错误。应该是:
function openGallery(url)
{
$.colorbox({width:"80%", height:"80%", iframe:true, href:"/pagetoopen.html"});
}
var
仅用于声明函数体中的局部变量。函数参数会自动声明为本地参数,因此此处不使用var
关键字。尝试包装传递给函数的字符串:
<td>
<?php if($ring["bandPaths"] != '')
echo '<input id="bandImage" type="image" src="http://thevowapp.com/iphoneapp/vowstore/bands/'. $ring['bandPaths'] .'" onClick="openGallery(\''.$ring['bandPaths'].'\');" style="width:100px; height:100px; margin-left: 10px;">'; ?>
</td>
请注意\'包装字符串。在PHP之前将
移动到
中。您能给我们一个实时演示吗?@MariM它仍然是相同的var url
在参数列表中无效,它应该是url
。但是函数没有使用它的参数。$ring['bandpath']
的类型是什么?如果它是一个字符串,您需要在onclick
属性中用引号括起来