开发者

Dynamic font change in a page using PHP

I want a script where I can change the font dynamically when the page is live from Arial to Times. Something 开发者_开发技巧like that. Can anyone please help me in this? Or can anyone please provide a script for this?


<?php
$font = "courier";

if(isset($_GET['font'])){
    $font = $_GET['font'];
}

?>

<a href="?font=arial">Arial</a> | 
<a href="?font=times">Times</a>

<div style="font-family: <?php echo $font; ?>">
the quick brown fox jumped over a lazy dog.
</div>

... although this might be a job for javascript, in some folks' opinion.


You could also do this with JavaScript

<html>
<head>
    <title>change font test</title>
</head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript">

    $(document).ready(function () {

        $(".changeFontArial").click(function () {
            $("body").css("font-family", "arial");

            return false;
        });
        $(".changeFontTimes").click(function () {
            $("body").css("font-family", "Times New Roman");

            return false;
        });
    });

</script>
<body>
    <p class="changeFontArial">
        Change to Arial</p>
    <p class="changeFontTimes">
        Change to Times</p>
</body>
</html>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜