开发者

Script with which I can change the font dynamically when the page is live using JavaScript

开发者 https://www.devze.com 2022-12-17 01:50 出处:网络
I want a JavaScript with which I can chang开发者_StackOverflowe the font dynamically when the page is live (Arial to Times). But when I click Arial or Times, the page should not get refreshed. Can any

I want a JavaScript with which I can chang开发者_StackOverflowe the font dynamically when the page is live (Arial to Times). But when I click Arial or Times, the page should not get refreshed. Can anyone please help me in this? Or can anyone please provide a script for this?


You should do this with javascript, not php. Use javascript to change the style of the text dynamically. Php is run on the server, and is therefor not in the picture for your no-reload scenario.

Example

Here is the first simple example google returned (e.g. search "javascript change text font" for more examples):

<html>
<body>
<div id=hey>
    <a onMouseover="document.getElementById('hey').style.fontFamily='courier'"> Make me COURIER!</a> ----
    <a onMouseover="document.getElementById('hey').style.fontFamily='verdana'"> Make me VERDANA!!!</a>
</div>
</body>
</html>


If you really want to use PHP and don't want the entire page to reload, you would need some form of AJAX implmentation.

However...your problem can be solved more easily with Javascript and I would recommend using that instead. The jQuery library allows you to change CSS styles with minimal code. There are a few code examples on changing style attributes on the jQuery website.

0

精彩评论

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

关注公众号