javascript在w3schools.com上运行但在jsfiddle.net上运行? [重复]

问题描述 投票:0回答:2

香港专业教育学院使用w3schools.com的基本示例来到这里: https://jsfiddle.net/02wu0v49/

function myFunction() {
  var x = document.getElementById("fname").value;
  document.getElementById("demo").innerHTML = "aaaaaa";
  document.getElementById("fname").value = "bbbbb";
  alert("lala3");
}
<body>

  <p>A function is triggered when the user releases a key in the input field. The function outputs the actual key/letter that was released inside the text field.</p>

  Enter your name: <input type="text" id="fname" onkeyup="myFunction()">

  <p>My name is: <span id="demo"></span></p>
</body>

不知何故w3schools版本有效,但它不会对jsfiddle做任何事情?

使用[code] [/ code]或者其他东西在stackoverflow上格式化代码真的很好......所有这些缩进都很糟糕。

javascript
2个回答
4
投票

enter image description here

将载入类型更改为No wrap in - <body>

这是更新的fiddle

这是Docs


0
投票

如果您在JS小提琴中打开浏览器控制台,它会列出错误。 HTML无法找到JS。

© www.soinside.com 2019 - 2024. All rights reserved.