ASP中字体设置问题?

ASP中字体设置问题?,第1张

如果你的DropDownList1里边的值写的是12px、14px、20px之类的,字体大小要这样转换:

Label1.Font.Size = int.Parse(DropDownList1.SelectedValue.Substring(0,2))

FontSize只能接收整型数据,要把字符串转换成整型才不会出错。

可以使用JavaScript加css来实现:

我帮你写了个示例

<html>

<head>

<title></title>

<style type="text/css">

.font1 {

font-size:12px

}

.font2 {

font-size:17px

}

</style>

<script type="text/javascript">

function changeFont(obj) {

if(obj.value=="大字体") {

obj.value="小字体"

document.getElementById("tab1").className="font2"

}

else {

obj.value="大字体"

document.getElementById("tab1").className="font1"

}

}

</script>

</head>

<body>

<input onclick="changeFont(this)" type="button" value="大字体" />

<table id="tab1" width="300">

<tr>

<td>a</td>

<td>b</td>

</tr>

<tr>

<td>c</td>

<td>d</td>

</tr>

<tr>

<td>e</td>

<td>f</td>

</tr>

</table>

</body>

</html>

第一个问题,字体问题:

示例换个标签:<h1 style="font-size:9pxcolor:#FF0000">123</h1><h1 style="font-size:100pxcolor:#0033cc">123</h1>

示例原标签:<font style="font-size:9pxcolor:#FF0000">123</font ><font style="font-size:100pxcolor:#0033cc">123</font >

========================================

里面的font-size:9px 是设置字体大小,跟你原来的size=9是不一样的,你的是字体号大小,我的源码是像素大小,你自己体会下,这是style的CSS内联写法

========================================

如何你写出网站来想要显示字体为方正超粗黑体的话,需要借助JS实现吧,其实一般宋体还是用的很多的,基本所有电脑都支持!


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/11209684.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存