[转贴]如何用js找到Div或TextBox原来的设定值?
用 javascript 对一个<div>进行如下操作:document.getElementById("divTest").width=50;
<div id ="divTest" width="100"></div>
我要怎么得到 divTest 原来的 width ??
我记得 Web Workshop 用一张表格记录了“当前值”与“初始值”的异同
<html>
<head>
<title></title>
<script language="javascript">
<!--
function changeValue()
{
divTest.runtimeStyle.width ="200";
txtTest.value="我变";
}
function getOriginal()
{
var str ="txtTest 的当前值为:" + txtTest.value +"\n";
str += "txtTest 的初始值为:"+txtTest.defaultValue+"\n\n";
str += "divTest 的当前宽度为:"+divTest.currentStyle.width+"\n";
str += "divTest 的初始宽度为:"+divTest.style.width
alert(str);
}
//-->
</script>
</head>
<body>
<INPUT id="Button1" type="button" value="改变属性" name="Button1" onclick="changeValue()"> <INPUT id="Button2" type="button" value="获取原始属性" name="Button2" onclick="getOriginal()">
<br/>
<INPUT id="txtTest" type="text" name="txtTest" value="文本测试">
<div style="BORDER-RIGHT: blue 2px solid; BORDER-TOP: blue 2px solid; BORDER-LEFT: blue 2px solid; WIDTH: 80px; BORDER-BOTTOM: blue 2px solid"
id="divTest">测试 DIV</div>
</body>
</html>