请问下关于Dom中的范围问题,为什么selectNode()返回undefined

js高级程序设计第332页

我用的谷歌浏览器

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

</head>

<body>

<p id="p1"><b>hello</b>word</p>

<script>

var range1 = document.createRange(),


    p1 = document.getElementById("p1");

var s=range1.selectNode(p1);

console.log(s)//返回undefined


</script>

</body>

</html>


我要去幼儿园深造了
浏览 1447回答 1
1回答

pardon110

建议如下:代码考虑浏览器的兼容性Range 对象被建立,在使用他的方法之前先去设置他的临界点。
打开App,查看更多内容
随时随地看视频慕课网APP