溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

javascript怎么設(shè)置字體效果

發(fā)布時間:2021-06-10 10:34:33 來源:億速云 閱讀:147 作者:小新 欄目:web開發(fā)

小編給大家分享一下javascript怎么設(shè)置字體效果,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

在javascript中,可以使用style屬性設(shè)置字體效果,語法格式“對象.style.屬性=屬性值”。Style對象代表一個單獨的樣式聲明??蓮膽?yīng)用樣式的文檔或元素訪問Style對象。

本教程操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function over(obj){
	obj.style.backgroundColor="blue";
	obj.style.color="white";
}
function out(obj){
	obj.style.backgroundColor="";
	obj.style.color="";
}
function win(){
	p1.style.fontWeight="Bold";//粗體
	p2.style.fontStyle="Italic";//斜體
	p3.style.textDecoration="underline";//下劃線
	p4.style.textDecoration="line-through";//刪除線
}
function qs(){
	p1.style.fontWeight="normal";
	p2.style.fontStyle="normal";
	p3.style.textDecoration="none";
	p4.style.textDecoration="none";
}
</script>
</head>
<body οnlοad="win();">
<table border="1" cellspacing="0" width="234" height="77">
<tr align="center" id="t1" οnmοusemοve="over(this);" οnmοuseοut="out(this);">
<td width="52"> </td>
<td width="65">商品</td>
<td width="95">價格(元)</td>
</tr>
<tr align="center" id="t2" οnmοusemοve="over(this);" οnmοuseοut="out(this);">
<td>A 商場</td>
<td>S 商品</td>
<td>100</td>
</tr>
<tr align="center" id="t3" οnmοusemοve="over(this);" οnmοuseοut="out(this);">
<td>B 商場</td>
<td>S 商品</td>
<td>80</td>
</tr>
</table>
<p id="p1">阿帕奇</p>
<p id="p2">阿帕奇</p>
<p id="p3">阿帕奇</p>
<p id="p4">阿帕奇</p>
<p id="p5" οnmοusemοve="qs();">鼠標(biāo)移到此處撤銷 阿帕奇樣式</p>
<p id="p6">阿帕奇</p>
</body>
</html>

在很多情況下,都需要對網(wǎng)頁上元素的樣式進行動態(tài)的修改。在JavaScript中提供幾種方式動態(tài)的修改樣式,下面將介紹方法的使用、效果、以及缺陷。

1、使用obj.className來修改樣式表的類名。

2、使用obj.style.cssTest來修改嵌入式的css。

3、使用obj.className來修改樣式表的類名。

4、使用更改外聯(lián)的css文件,從而改變元素的css

以上是“javascript怎么設(shè)置字體效果”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI