我已经在变量中存储整个url尝试了另一个代码。它给我一个错误,如“Uncaught SyntaxError:意外的输入结束”
<?php
$url=$item['item_url'];
$title=$item["item_title"];
$str_url='http://www.facebook.com/sharer.php?u='.$url.'&t='.$title;
?>
<script>
var str_url = "'<?php echo $str_url; ?>'";
var title = "'<?php echo $title; ?>'";
var social_icon ="<div class='display-social-button'><a class='uk-icon-button uk-icon-facebook' onclick='popupCenter('"+ str_url + "','" + title + "','450','450');' href='javascript:void(0);'></a></div>";
</script>
答案 0 :(得分:-2)
您需要在onclick
中的变量周围添加引号var social_icon ="<div class='display-social-button'><a class='uk-icon-button uk-icon-facebook' onclick='popupCenter(\"http://www.facebook.com/sharer.php?u="+ str_url + "&t="+ title + ","+title+"\",450,450);' href='javascript:void(0);'></a></div>";
也就是说,不建议使用onclick事件来锚定。我建议使用锚点的href和target标记。