日期:2014-05-17  浏览次数:20803 次

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时,输入分号好,再按一下空格键,就可以弹出属性列表供选择;不然的话,则不会出现属性列表,必须手动输入,如果对属性不熟,就比较麻烦,有时候会不知道有哪些属性。
【推荐原因: 方法二的onload="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" onload="getHeight()">
WITH的意思是{}里面就可以省略掉with()里()的对象了。

 

设置背景透明色:

using System.