阔活洵信 2015-06-15 07:25 采纳率: 0%
浏览 1710

用JS创建的元素:focus在IE之除外的浏览器无效

元素是这么来的:

 var rootDiv = document.createElement("div");
 rootDiv.setAttribute("id", list[i].ID);
 rootDiv.setAttribute("class", "extent");

 var div = document.createElement("div");
 var input = document.createElement("input");
 input.setAttribute("type", "image");
 input.setAttribute("src", "/Content/Images/check.png");
 var p1 = document.createElement("p");
 var p2 = document.createElement("p");
 p1.setAttribute("class", "pinfo");
 p2.setAttribute("class", "pinfo");
 p1.innerHTML = "时间:" + new Date(list[i].SUBTIME).format("yyyy年MM月dd日");
p2.innerHTML = "备注:" + list[i].REMARK;
rootDiv.appendChild(input);
rootDiv.appendChild(div);
div.appendChild(p1);
div.appendChild(p2);
panel.appendChild(rootDiv);

css 是这样的:

 .extent:focus {
    border:2px solid #96C2F1;
    background-color: #EEFAFF
}

结果是在IE中,这是有效果的,但是在FF,CHROME等浏览者中没效果。还有就是如果我只是把那些元素直接写入HTML,也是有效果的

  • 写回答

1条回答

  • lhl_lqc 2015-06-15 07:58
    关注

    ie、chrome、firefox的添加元素和样式的语法不一样,你要想兼容,可以通过jquery进行添加试试。

    评论

报告相同问题?

悬赏问题

  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗