如何用js改变中的文字
2个回答
展开全部
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<style>
div{
width: 240px;
height: 80px;
margin: 20px;
padding: 20px;
border: 1px solid #d5d5d5;
}
</style>
<script type="text/javascript">
function changeFont(){
setFont({
id:"test1",
color:"#ff0000",
size: "12px",
family:"微软雅黑"
});
setFont({
id:"test2",
color:"#00ff00",
size: "12px",
family:"楷体",
weight: "normal"
});
setFont({
id:"test3",
color:"#0066ff",
size: "12px",
family:"隶书"
});
}
function setFont(settings){
if(settings && settings.id){
var obj = document.getElementById(settings.id);
obj.style.color= settings.color || '#ffff00';
obj.style.fontSize = settings.size || '36px';
obj.style.fontFamily = settings.family || 'Courier New';
obj.style.fontWeight = settings.weight || 'bolder';
//或者
//document.getElementById("test1").style.font="italic bold 12px arial,serif";
}
}
</script>
</head>
<body>
<div id="test1">这是一个测试1</div>
<div id="test2">这是一个测试2</div>
<div id="test3">这是一个测试3</div>
<button onclick="changeFont();">Change</button>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询