如何获取div宽度

wctmac123 2014-10-15 09:52:27
div = this.div_ = document.createElement("div");
div.style.border = "0px none";
div.style.position = "absolute";
div.style.width = this.width_ + "px";
div.style.height = this.height_ + "px";
if(this.html_.length>50)
{
div.style.zIndex=xindex++;
}else
{
div.style.zIndex=1;
}
var contentDiv = document.createElement("div");
var hhtml= ' <div id="test" style="padding: 7px 5px;*padding: 7px 3px; background:#ffffff; border: 1px solid #606060; position: relative;'+
'-moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px;">'+
'<span style="width: 0; height: 0; left:63px; font-size: 0; overflow: hidden; position: absolute;'+
'border-width: 10px; border-style: solid dashed dashed; border-color: #606060 transparent transparent;'+
'bottom: -20px;"></span><span style="width: 0; height: 0; left:63px; font-size: 0; overflow: hidden;'+
'position: absolute; border-width: 10px; border-style: solid dashed dashed; border-color: #ffffff transparent transparent;'+
'bottom: -19px;"></span><div id='+this.id+'>'+this.html_+'</div></div>';


contentDiv.innerHTML = hhtml;
div.appendChild(contentDiv);
div.style.display = 'none';
panes.floatPane.appendChild(div);
this.panMap();

我要获取这个 id为test的div的宽度,我的这个div宽度是根据this.html_传过来的值决定的
但是我用 $("#test").width()无法获取,该如何
...全文
207 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
MnZlZ 2014-10-15
  • 打赏
  • 举报
回复
我要获取这个 id为test的div的宽度,我的这个div宽度是根据this.html_传过来的值决定的 但是我用 $("#test").width()无法获取,该如何///////////////////////////////////////////////////////////////////////////

var test=document.getElementById("test");
test.setAttribute("width",this.html_);
之后就用test.getAttribute("width");得到宽度
KeepSayingNo 2014-10-15
  • 打赏
  • 举报
回复
你看看 $("#test")这个是否有对象,如果没有,就用document.getElementById()获取
slwsss 2014-10-15
  • 打赏
  • 举报
回复
test 添加到document 后再获取
低下头8吻你 2014-10-15
  • 打赏
  • 举报
回复

var width=$("#id").attr("width");

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧