美文网首页
封装节点兼容代码

封装节点兼容代码

作者: inspg | 来源:发表于2019-03-26 21:29 被阅读0次

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title></title>

</head>

<body>

<ul id="uu">

<li>我手机</li>

<li>我手机</li>

<li>我手机</li>

</ul>

</body>

<script src="common.js">

</script>

<script type="text/javascript">

function getFirstChild(parent){

if(parent.firstElementChild!=undefined){

return parent.firstElementChild;

}else{//IE8支持的只有firstchid即第一个节点

var node=parent.fisrtChild;

if(node&&node.nodetype!=1){//1是元素

node=node.nextSibling; 

}

return

}

}

function getLastChild(parent){

if(parent.lastElementChild!=undefined){

return parent.lastChild;

}else{

var node=node.lastChild;

if(node&&node.nodetype!=1){

node=node.previousSibling;

}

return node;

}

}

console.log(getFirstChild(my$("uu")));

console.log("666");

</script>

</html>

相关文章

网友评论

      本文标题:封装节点兼容代码

      本文链接:https://www.haomeiwen.com/subject/cotovqtx.html