Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 动态创建Div,高于其他Div_Php_Javascript_Ajax_Html - Fatal编程技术网

Php 动态创建Div,高于其他Div

Php 动态创建Div,高于其他Div,php,javascript,ajax,html,Php,Javascript,Ajax,Html,该脚本每隔一秒钟就会使用AJAX打开一个页面,并将内容返回到该页面上的一个新div中,该div是动态创建的。但不幸的是,他们在一起了。我想在顶部创建每个新div。我真的不想使用jquery或任何类似的东西 非常感谢您提供的任何帮助,我对JS不是很有信心,所以如果不清楚原因,请您也给我一个小的解释。:)谢谢 函数timedCount() { 最小值=数学楼层(s/60); 秒=秒-(最小*60); 如果(秒=60){min=min-15;} 如果(quit==0){document.getElem

该脚本每隔一秒钟就会使用AJAX打开一个页面,并将内容返回到该页面上的一个新div中,该div是动态创建的。但不幸的是,他们在一起了。我想在顶部创建每个新div。我真的不想使用jquery或任何类似的东西

非常感谢您提供的任何帮助,我对JS不是很有信心,所以如果不清楚原因,请您也给我一个小的解释。:)谢谢

函数timedCount()
{
最小值=数学楼层(s/60);
秒=秒-(最小*60);
如果(秒<10){sec='0'+sec;}
如果(min>=60){min=min-15;}
如果(quit==0){document.getElementById('mTime').innerHTML=min+':'+sec;}
s=s+1;
var ajaxRequest;
尝试{ajaxRequest=newXMLHttpRequest();}catch(e){
尝试{ajaxRequest=newactivexobject(“Msxml2.XMLHTTP”);}catch(e){
请尝试{ajaxRequest=newactivexobject(“Microsoft.XMLHTTP”);}catch(e){
警告(“你的浏览器坏了!”);
返回false;
}
}
}
ajaxRequest.onreadystatechange=函数()
{
if(ajaxRequest.readyState==4&&ajaxRequest.responseText!='')
{
如果(ajaxRequest.responseText=='HT'){
document.getElementById('mTime').innerHTML='Half Time';
t=设置超时(“timedCount()”,(3600-s)*1000);
退出=1;
返回;
}
如果(ajaxRequest.responseText=='FT'){
document.getElementById('mTime')。innerHTML='Full Time';
退出=1;
返回;
}
el=document.createElement('rep'+i);
el.innerHTML=ajaxRequest.responseText+'
'; document.getElementById('container').appendChild(el); i=i+1; } } 打开(“GET”,“getMatch.php”,true); ajaxRequest.send(空); }
您想要该功能吗


请注意,如果parent为空,parent.firstChild因此为空,则el将插入parent的末尾,这是您想要的。

您是否尝试过使用
insertBefore

您可以更改行:

document.getElementById('container').appendChild(el);


container.firstChild
将为您提供对容器中第一个元素的引用,并在其前面放置
el

appendChild方法始终在集合的末尾添加新节点,这就是它出现在bottom的原因-请参阅


使用此处记录的insertBefore方法:。您可以使用document.getElementById('container').firstChild作为第二个参数

通常,如果我真的想在所有其他元素上加一个div,我会使用css位置和z索引,如:

div{
position: absolute;
z-index: 9999;
}

:)

对于缺少代码注释表示歉意。我对其他解决方案投了赞成票,因为它们完全正确。在平板电脑上打字很糟糕,而且要花很长时间!确实要
el=document.createElement('rep'+i)?这将创建类似于
的元素。我猜您想要
el=document.createElement('div');el.id=代表+i或者什么的。
document.getElementById('container').appendChild(el);
var container = document.getElementById('container');
container.insertBefore(el, container.firstChild);
div{
position: absolute;
z-index: 9999;
}