87,910
社区成员
发帖
与我相关
我的任务
分享
<!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>
<script type="text/javascript">
function FixWidth(selectObj){
var newSelectObj = document.createElement("select");
newSelectObj = selectObj.cloneNode(true);
newSelectObj.setAttribute("ID", "aa");
newSelectObj.selectedIndex = selectObj.selectedIndex;
newSelectObj.onmouseover = null;
var e = selectObj;
var absTop = e.offsetTop;
var absLeft = e.offsetLeft;
while(e = e.offsetParent){
absTop += e.offsetTop;
absLeft += e.offsetLeft;
}
var widthTemp = "";
//if(absLeft >= 200px){
// widthTemp ="";
// }else{
// widthTemp = 200px;
// }
with (newSelectObj.style){
position = "absolute";
top = absTop + "px";
left = absLeft + "px";
width = widthTemp;
}
var rollback = function(){ RollbackWidth(selectObj, newSelectObj); };
newSelectObj.onmouseout= rollback;//新增加的事件,解决一处BUG
newSelectObj.focus();
newSelectObj.onfocus = function(){ newSelectObj.onmouseout=null; };//新增加的事件,解决BUG
newSelectObj.onblur = rollback;
newSelectObj.onchange = rollback;
selectObj.style.visibility = "hidden";
document.body.appendChild(newSelectObj);
}
function RollbackWidth(selectObj, newSelectObj){
selectObj.selectedIndex = newSelectObj.selectedIndex;
selectObj.style.visibility = "visible";
document.body.removeChild(newSelectObj);
}
</script>
</head>
<body>
<form method="post">
<select name="Select1" style="width:200px;" onmouseover="FixWidth(this)">
<option id="C" title="this is C">CCC发送</option>
</div>
</form>
</body>
</html>