使用谷歌浏览器,如果你console.log是一个对象,它可以让你检查控制台中的元素.例如:
var a = { "foo" : "bar", "whiz" : "bang" };
console.log(a);
Run Code Online (Sandbox Code Playgroud)
Object通过单击旁边的箭头打印出可以检查的内容.但是,如果我尝试记录HTMLElement:
var b = goog.dom.query('html')[0];
console.log(b);
Run Code Online (Sandbox Code Playgroud)
<html></html>通过单击旁边的箭头打印出无法检查的内容.如果我想看到JavaScript对象(带有方法和字段)而不仅仅是元素的DOM,我该怎么做?
javascript google-chrome developer-tools google-closure-library
我偶然发现了一个 js 项目,我需要使用 javascript 在 html 标签标签内设置值。我尝试了以下代码,但由于某种原因它不起作用。知道为什么吗?
<label id="text"></label>
<script>
document.getElementById('text').value = 'Hello World!';
</script>
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。
<!DOCTYPE html>
<html>
<body>
<p>Click the button to create an Input field.</p>
<button id="btn" onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var y = document.createElement("LABEL");
var yv = prompt("Enter Caption value:", "");
y.setAttribute("value", yv);
document.body.appendChild(y);
}
</script>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
我想使用上面的代码创建“lebel”。它不起作用。请帮忙...