我自己做了一个用户控件,通过点击按钮来动态添加,现在遇到一个问题,我希望点击按钮的同时使得DIV的高度也增加,结果测试发现Firefox下点击按钮的时候高度增加了后马上又变回原来的高度了,而在IE6中高度可以持续增加,代码如下
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function AddHeight()
{
var div = document.getElementById("container");
var height=div.clientHeight ;
alert(height);
height+=200;
alert(height);
div.style.height=height+"px";
}
</script>
</head>
<body>
<form id="form1" runat="server"> <div id="container" runat="server" style="width:700px;height:200px; background-color:#469ff3"></div>
<div style=" background-color:Red;">
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click1" OnClientClick="AddHeight()" />
</div>
<div>
<asp:Label ID="txt" runat="server" Text=""></asp:Label></div>
</form>
</body>
</html>Firefox下的效果是:先弹出200,然后弹出400,DIV的高度变为400然后又立刻变为200,不论点击按钮多上次都是这样,请高手赐教
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function AddHeight()
{
var div = document.getElementById("container");
var height=div.clientHeight ;
alert(height);
height+=200;
alert(height);
div.style.height=height+"px";
}
</script>
</head>
<body>
<form id="form1" runat="server"> <div id="container" runat="server" style="width:700px;height:200px; background-color:#469ff3"></div>
<div style=" background-color:Red;">
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click1" OnClientClick="AddHeight()" />
</div>
<div>
<asp:Label ID="txt" runat="server" Text=""></asp:Label></div>
</form>
</body>
</html>Firefox下的效果是:先弹出200,然后弹出400,DIV的高度变为400然后又立刻变为200,不论点击按钮多上次都是这样,请高手赐教
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页 </title>
<script type="text/javascript">
function AddHeight()
{
var div = document.getElementById("container");
var height=div.clientHeight ;
alert(height);
height+=200;
alert(height);
div.style.height=height+"px";
}
</script>
</head>
<body>
<form id="form1" runat="server"> <div id="container" runat="server" style="width:700px;height:200px; background-color:#469ff3"> </div>
<div style=" background-color:Red;">
<input type="button" value="Button" onclick="AddHeight()" />
</div>
<div>
</div>
</form>
</body>
</html>
有可能它把这个当成字符串了,而不是数值.