-1

我正在使用的标签系统(链接)

简单地说内联标签永远不会被云取代

我从文件夹中加载了我的 JS(已确认链接)

<script type="text/javascript" src="/jquery/jqquery-1.7.2.js"></script>
<script type="text/javascript" src="/jquery/jqcloud-1.0.1.js"></script>
<link rel="stylesheet" href="/jquery/jqcloud.css" type="text/css" media="screen">

然后我使用一些 PHP 来生成标签数组

<script type="text/jscript">
var word_list = [
<?
foreach ($array as $key => $value) {
if ($value == $average) { $weight = 2;} 
else if ($value > $average) { $weight = 3;} 
else if ($value < $average) { $weight = 1;}
if (strlen($key) > 1 ){
  echo "{text: \"".$key."\", weight:".$weight.", url: \"http://myurl.com/tags/".$key."\", title: \"".$value."\"}";
  $total -= 1;
  if ($total == 0) echo ",";
}
}
?>
];
$(document).ready(function() {
    $("#wordcloud").jQCloud(word_list);
});

然而,我的标签部分只有一个空 div

http://jsfiddle.net/K28Mc/ 运行示例

4

2 回答 2

1

问题似乎是你永远不会关闭你的数组:

var word_list = [ // <-Note this character..
<?
foreach ($array as $key => $value) {
if ($value == $average) { $weight = 2;} 
else if ($value > $average) { $weight = 3;} 
else if ($value < $average) { $weight = 1;}
if (strlen($key) > 1 ){
  echo "{text: \"".$key."\", weight:".$weight.", url: \"http://myurl.com/tags/".$key."\", title: \"".$value."\"}";
  $total -= 1;
  if ($total == 0) echo ",";
}
}
?>
}; //<------- Right here, you fail to close the array.  This should be a ].  I have a feeling this is breaking everything else.
$(document).ready(function() {
    $("#wordcloud").jQCloud(word_list);
});
于 2012-09-13T20:56:13.887 回答
0
foreach ($result['keywords'] AS $k => $keyword ) 
{

 $font_size = rand(10, 25);
 $fonts = array("Helvetica", "Arial", "Courier", "Georgia", "Serif", "Comic Sans", "Tahoma",  "Roman", "Modern");
 shuffle($fonts);
$randomFont = array_shift($fonts);
echo ' <a href="" title="' . $keyword['name'] . '">' . '<span style="font-family:' . $randomFont . '; font-size:'.$font_size.'px;">' . $keyword['name'] . '&nbsp;</span></a>';
}
于 2013-03-19T16:08:24.213 回答