我试图找出如何让浏览器显示视频元素的选择?
下面的示例 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 m