如何在不使用getElementById方法的情况下测试元素是否存在?我已经设置了一个现场演示供参考.我也会在这里打印代码:
<!DOCTYPE html>
<html>
<head>
<script>
var getRandomID = function (size) {
var str = "",
i = 0,
chars = "0123456789abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ";
while (i < size) {
str += chars.substr(Math.floor(Math.random() * 62), 1);
i++;
}
return str;
},
isNull = function (element) {
var randomID = getRandomID(12),
savedID = (element.id)? element.id : null;
element.id = randomID;
var foundElm = document.getElementById(randomID);
element.removeAttribute('id');
if (savedID !== null) {
element.id = savedID;
}
return (foundElm) ? false : true; …Run Code Online (Sandbox Code Playgroud) 我需要的信息是元标记.如何"content"在何时访问元标记的数据property="video"?
HTML:
<meta property="video" content="http://video.com/video33353.mp4" />
Run Code Online (Sandbox Code Playgroud)