插件85:切换文本内容

<?php // Plug-in 85: Toggle Text

// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link

$text1 = " Photosynthesis is a process that converts carbon ".
         "dioxide into organic compounds, especially sugars, " .
         "using the energy from sunlight.";
$link1 = "Choose long definition";
$text2 = "$text1 Photosynthesis occurs in plants, algae, and " .
         "many species of Bacteria, but not in Archaea. Photo" .
         "synthetic organisms are called photoautotrophs, " .
         "since it allows them to create their own food. In " .
         "plants, algae and cyanobacteria photosynthesis uses " .
         "carbon dioxide and water, releasing oxygen as a " .
         "waste product. Photosynthesis is vital for life on " .
         "Earth. As well as maintaining the normal level of " .
         "oxygen in the atmosphere, nearly all life either " .
         "depends on it directly as a source of energy, or " .
         "indirectly as the ultimate source of the energy in " .
         "their food.";
$link2 = "Choose short definition";

echo "<h2>Robin's gardening website</h2>";
echo "<h3>The sun and photosynthesis</h3>";

echo PIPHP_ToggleText($text1, $link1, $text2, $link2);

echo "<h3>Pollination</h3>";
echo "...etc...";

function PIPHP_ToggleText($text1, $link1, $text2, $link2)
{
   // Plug-in 85: Toggle Text
   //
   // This plug-in takes two pairs of details each comprising
   // a text and a link. When clicked the link text for each
   // causes the other text and link to be displayed, thus
   // toggling between the two. It returns the JavaScript
   // necessary to insert in your web page to achieve this
   // effect. It requires these arguments:
   //
   //    $text1: The original text to display
   //    $link1: The original link text to display
   //    $text2: The alternative text
   //    $link2: the alternative link text

   $tok = rand(0, 1000000);
   $out   = "<div id='PIPHP_TT1_$tok' style='display:block;'>" .
            "<a href=\"javascript://\" onClick=\"document." .
            "getElementById('PIPHP_TT1_$tok').style.display=" .
            "'none'; document.getElementById('PIPHP_TT2_$tok')" .
            ".style.display='block';\">$link1</a>$text1</div>\n";

   $out  .= "<div id='PIPHP_TT2_$tok' style='display:none;'>" .
            "<a href=\"javascript://\" onClick=\"document." .
            "getElementById('PIPHP_TT1_$tok').style.display=" .
            "'block'; document.getElementById('PIPHP_TT2_$tok')" .
            ".style.display='none';\">$link2</a>$text2</div>\n";
   return  $out;
}

?>

插件说明:

当鼠标单击超链接时,插件在两组文本(或HTML)之间进行切换。他需要以下参数:

$text1:显示的页面主文本。

$link1 显示在页面的主超链接文本。

$text2 另一个文本。

$link2 另一个超链接文本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值