我对某个功能有疑问。
function &formatName($id, $name, $clanId, $clanSym, $clanCol)
{
static $cache = array();
if (!isset($cache[$name])) {
$cache[$name] = esc($name);
if ($id !== NULL) {
$cache[$name] = '<a href="' . esc('player_info.php?target=' . $id) .
'">' . $cache[$name] . '</a>';
} else {
$cache[$name] = "<s>{$cache[$name]}</s>";
}
if ($clanId !== NULL && $clanId != 0) {
$cache[$name] = "(<span style=\"color: #$clanCol;\">" .
htmlentities($clanSym) . "</span>) " . $cache[$name];
}
}
return $cache[$name];
}
//打印$ player
的可点击名称function print_name($player)
{
global $db_name, $user_options;
static $cache = array();
if (!isset($cache[$player['login_name']])) {//this user not cached
$pQuery = mysql_query("select u.login_id, u.login_name, u.clan_id, u.clan_sym_color,u.clan_sym from ${db_name}_users u where u.login_id = '$player[login_id]'");
$player = mysql_fetch_assoc($pQuery);
$cache[$player['login_name']] = formatName($player['login_id'],
$player['login_name'], $player['clan_id'], $player['clan_sym'],
$player['clan_sym_color']);
}
return $cache[$player['login_name']];
}
上述功能会打印一个包含玩家姓名的链接。 我想在链接上放置一张桌子或某种装饰背景。 我能做到这一点吗? 谢谢你的阅读。
答案 0 :(得分:0)
您可以在链接周围放置一个范围,并添加样式,这样可以比链接样式更灵活。
$cache[$name] = '<span style="background-image: url(image.jpg);"><a href="' . esc('player_info.php?target=' . $id) . '">' . $cache[$name] . '</a></span>';
答案 1 :(得分:0)
只需更改行:
$cache[$name] = '<a href="' . esc('player_info.php?target=' . $id) . '">' . $cache[$name] . '</a>';
到
$cache[$name] = '<span class="link-decorator">';
$cache[$name] .= '<a href="' . esc('player_info.php?target=' . $id) .
'">' . $cache[$name] . '</a>';
$cache[$name] .= '</span>';
然后,您可以使用CSS设置链接和周围范围的样式:
span.link-decorator { border: 3px solid #789abc; }
span.link-decorator a { color: red; }
span.link-decorator a:hover { color: blue; }
span.link-decorator a:visited { color: green; }