jscript很难编写一个简单的代码



我无缘无故地很难使用这个简单的jscript。这段代码应该在单击后显示时间。但我得到了下面的误差。我做错了什么

{
"message": "Uncaught TypeError: Cannot set properties of null (setting 'innerHTML')",
"filename": "https://stacksnippets.net/js",
"lineno": 30,
"colno": 43
}

function item(name)
{
var d = new Date();
document.getElementById("but1").innerHTML = d;
}
<!DOCTYPE html>
<html>
<body>
<script src="C:Userskalyanasundar.sOneDrive - HCL Technologies LtdDesktopprojanimationindex.Js"></script>
<h2>JavaScript Statements</h2>
<p id="demo">You cannot break a code line with a  backslash.</p>
<button onclick="item(name)">Try it</button>

</body>
</html>

这个id (#but1)不存在,所以innerHtml不能工作,试着改变它

function item(name) {
var d = new Date();
document.getElementById("demo").innerHTML = d;
}
<!DOCTYPE html>
<html>
<body>
<script src="C:Userskalyanasundar.sOneDrive - HCL Technologies LtdDesktopprojanimationindex.Js"></script>
<h2>JavaScript Statements</h2>
<p id="demo">You cannot break a code line with a  backslash.</p>
<button onclick="item(name)">Try it</button>

</body>
</html>

相关内容

  • 没有找到相关文章

最新更新