日期:2014-05-16 浏览次数:20659 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
*{
margin:0;
padding:0;
}
body{
font-size:12px;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
</head>
<body>
<div class="div1" style="float:left;border:1px solid red;width:auto;">
<div class="div11" style="float:left;border:1px solid green;width:auto;">
ddddddddddddddfasssss
</div>
<input type="text" class="input11" style="float:left;border:1px solid blue;" />
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.box{width:500px;margin:100px auto;height:22px;line-height:22px;}
.box span{float:left;}
.box input{float:left;border:solid 1px #ccc; margin:0;height:22px;}
</style>
<script>
window.onload=function()
{
var oBox=document.getElementById('box');
var oSpan=oBox.getElementsByTagName('span')[0];
var oText=oBox.getElementsByTagName('input')[0];
oText.style.width=getStyle(oBox,"width")-getStyle(oSpan,"width")-2*getStyle(oText,"borderLeftWidth")+'px';
}
function getStyle(obj,attr)
{
if(obj.currentStyle)
return parseFloat(obj.currentStyle[attr])
------解决方案--------------------
0;
return parseFloat(getComputedStyle(obj,0)[attr])
------解决方案--------------------
0;
}
</script>
</head>
<body>
<div class="box" id="box">
<span>测试测试测试测绘试测绘试测绘</span>
<input type="text" />
</div>
</body>
</html>