Implementing fancybox onclick()


Implementing fancybox onclick()

<?php
   echo '<td class="options-width">'.
        '<a href="edituser_lightbox.php?user_id=' . $row['user_id'] . ' " onclick:"  $.fancybox({ href:'example.jpg',title : 'Custom Title'});"title="Edit" class="icon-1 info-tooltip" </a>'.
        '<a href="deleteuser.php?user_id=' . $row['user_id'] . ' " class="icon-2 info-tooltip">   </a>'.
        '<a href="" title="Save" class="icon-5 info-tooltip">     </a>'.
        '</td>';

   echo "</tr>";
  }
?>

伙计们,我至少要靠近这里?你能看到我想做什么吗?我也无法更改我的 css 以包含花式框:(

onclick 属性应使用 = 指定,而不是:如下:

echo '<a href="edituser_lightbox.php?user_id=' . $row['user_id'] . '" onclick="$.fancybox({ href:''example.jpg'',title : ''Custom Title''});" title="Edit" class="icon-1 info-tooltip" </a>';

在 fancybox 语句中,您还需要对单引号进行反斜杠转义,以便它们在输出 HTML 中显示为文字'。在 href= 属性的结束"之前,您还有一个额外的空格。

JavaScript 内联放置在标签中不被认为是好的做法。相反,最好将其绑定为:

$("a#editLink").click(function() {
   $.fancybox({ href:'example.jpg',title : 'Custom Title'});
});

请注意,您需要将id="editLink"添加到<a>标记中。(它可以是任何id,也可以是各种其他jQuery选择器,而不是id

echo '<a id="editLink" href="edituser_lightbox.php?user_id=' . $row['user_id'] . '" onclick="$.fancybox({ href:''example.jpg'',title : ''Custom Title''});" title="Edit" class="icon-1 info-tooltip" </a>';
看起来像

一个错字:

onclick:"

将冒号设为等号:

onclick="

此外,通过添加引号来确保对象的属性值为字符串。

onclick='$.fancybox({href: "'example.jpg'", title: "'Custom Title'"});'