【问题标题】:Dynamically adding HTML using .innerHTML (formatting issue in IE7)使用 .innerHTML 动态添加 HTML(IE7 中的格式问题)
【发布时间】:2013-02-07 15:02:34
【问题描述】:

我有一个选择下拉菜单,在更新时会采用新变量并动态更新其正下方的 div。

这里是我的选择输入:

<select name='region_name' onchange='showDistrict(this.value)'>

这是我控制动态内容的 javascript:

<script>
function showDistrict(str)
{
if (str=="")
  {
  document.getElementById("district_div").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("district_div").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getdistrict.php?q="+str,true);
xmlhttp.send();
}
</script>

getdistrict.php?q= 页面执行另一个 MySQL 调用并将信息循环输出到 div“district_div”我的问题是...该 div 区域在 IE 7 中无法正确拉伸。 所以我的动态数据覆盖了它下面的所有内容。

当我使用 firebug 查看源代码时,我什至看不到来自 innerHTML 的新 html,所以我不确定这是 CSS 问题还是与 .innerHTML 有关的问题

【问题讨论】:

  • 你为 div 赋予了什么 CSS?
  • 正如你所解释的,它看起来像一个 CSS 问题......只需将固定宽度应用于 div 像素并再次检查。

标签: javascript html css input innerhtml


【解决方案1】:

不要给这个DIV设置任何width或者height,或者只设置min-width min-height,你也可以给这个DIV设置overflow:hidden

【讨论】:

  • 我稍微移动了我的 CSS,但我也按照上面的说明进行了操作。当我有更多时间时,我会发布我的css。谢谢你的帮助。 +1 已选中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多