javascript在w3schools.com上运行但在jsfiddle.net上运行?

时间:2017-12-20 05:55:30

标签: javascript

我使用了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上格式化代码真的很好......所有这些缩进都很糟糕。

2 个答案:

答案 0 :(得分:4)

enter image description here

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

此处已更新fiddle

这是Docs

答案 1 :(得分:0)

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