ASP.net中同时设置控件的多个属性,以及设置背景透明色。

设置控件的多个属性的方法一【推荐】:

<form id="form1" runat="server" style=" position:absolute; height:220px; width:400px; top:300px; left:650px; background:#87CEEB">
<div style="position:absolute;height:40px;width:40px;background:yellow;left:80px;top:80px;"></div>

设置style时,输入分号好,再按一下空格键,就可以弹出属性列表供选择;不然的话,则不会出现属性列表,必须手动输入,如果对属性不熟,就比较麻烦,有时候会不知道有哪些属性。
【推荐原因: 方法二的οnlοad="getHeight()"这种方式,如果刷新很快的话,会闪屏,因为页面加载时控件的位置,和通过onload事件改变后控件的位置,不一样,一直点击刷新,会看到两处都与控件。方法一的方式,不会闪屏,即使闪屏,控件也在同一位置闪屏。方法一效果好。】

设置控件的多个属性的方法二:

<script type="text/javascript">
        function getHeight() {
            var form1 = document.getElementById("form1");
            //form1.style.height = screen.height / 4;
            //form1.style.width = screen.width / 3;
            with (form1.style) {
                position = "absolute";
                height = 220;
                width = 400;
                top = 300; 
                left = 650;
                backgroundColor = "#999999";// Transparent
            };        }
</script>
或者
<script type="text/javascript">
        function getHeight() {
            var form1 = document.getElementById("form1");
            with (form1) {
                style.position = "absolute";
                style.height = 220;
                style.left = 650;
                style.backgroundColor = Transparent";//设为背景透明
            };
         }
</script>

<body style="background-color:Teal" οnlοad="getHeight()">
WITH的意思是{}里面就可以省略掉with()里()的对象了。

 

设置背景透明色:

using System.Drawing;//用到Color时
aspx.cs中:
Label1.BackColor = Color.Transparent;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值