Javascript html元素上的DOM选择和范围

Javascript html元素上的DOM选择和范围,javascript,html,dom,range,selection,Javascript,Html,Dom,Range,Selection,我试图找出如何使浏览器显示视频元素的选择 下面的html页面示例与img标记的预期效果一样:完成onElementClick函数后,图像仍处于选中状态 我不知道如何用视频标签实现同样的效果。有可能吗 <!DOCTYPE html> <html> <head><title>Range</title></head> <body> How to select the video tag programmatic

我试图找出如何使浏览器显示视频元素的选择

下面的html页面示例与img标记的预期效果一样:完成onElementClick函数后,图像仍处于选中状态

我不知道如何用视频标签实现同样的效果。有可能吗

<!DOCTYPE html>
<html>
<head><title>Range</title></head>
<body>
    How to select the video tag programmatically?
    <video src="http://www.w3schools.com/html/movie.mp4" controls="controls" onmousedown="onElementClick(this)"></video>
    It is easy with 'img' (click the image):
    <img src="http://www.w3.org/2008/site/images/logo-w3c-mobile-lg" onclick="onElementClick(this)"></img>

    <script>
        function onElementClick(element) {
            var selection = window.getSelection();
            selection.removeAllRanges();
            console.log("[Before adding a range] clicked: %s; selection.type: %o, selection: %o", element.localName, selection.type, selection);

            var range = document.createRange();
            range.selectNode(element);
            selection.addRange(range);

            selection = window.getSelection();
            console.log("[After adding a range] selection after adding a range: %o, selection: %o", selection.type, selection);
            console.log("[After adding a range] window.getSelection(): %o",window.getSelection());
         }
    </script>

</body>
</html>
我使用的浏览器是Chrome v。28.0.1500.95米