我不知道这个JSFiddle有什么问题.
HTML:
<input type="button" value="test" onclick="test()">
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
function test(){alert("test");}
Run Code Online (Sandbox Code Playgroud)
当我点击按钮时 - 什么也没发生.控制台说"测试未定义"
我已经阅读了JSFiddle文档 - 它说添加了JS代码并添加了<head>HTML代码<body>(所以这个JS代码早于html并且应该工作).
我是javascript的新手,偶然发现了return关键字.基本上,这两个陈述的区别是什么?
<input type="checkbox" onclick="doAlert()" />
Run Code Online (Sandbox Code Playgroud)
VS
<input type="checkbox" onclick="return doAlert();" />
Run Code Online (Sandbox Code Playgroud)
从本质上讲,两者都返回了相同的结果并调用了函数,但还有更多吗?任何帮助非常感谢:).谢谢!
我试图删除ul(列表项)中的元素,因此只使用javascript.因为我动态生成html,所以我试图设置onclick,因为我在下面创建它.但是,当我尝试单击(请参阅小提琴)时,元素不会被删除.相关功能如下:
var appendHTML = function (el) {
var list = document.getElementById("events");
for (var i = 0; i < filteredDates.length; i++) {
var listItem = filteredDates[i].name;
listItem.className = "event-list";
listItem.setAttribute("onclick", "deleteEvent()");
list.appendChild(listItem);
}
};
var deleteEvent = function () {
var listItem = this.parentNode;
var ul = listItem.parentNode;
//Remove the parent list item from the ul
ul.removeChild(listItem);
return false;
};
Run Code Online (Sandbox Code Playgroud)
事实证明,noTone()和tone()在核心的arduino API中,但似乎没有为Arduino Due实现。我希望使用tone()并noTone()实现此处找到的马里奥死亡声音,但是当我添加代码并对其进行编译时,出现以下错误:
Run Code Online (Sandbox Code Playgroud)trenchRun:154: error: 'tone' was not declared in this scope trenchRun:156: error: 'noTone' was not declared in this scope
如果您有兴趣,这里有一个SSCCE,是在Mac OS X 10.8上针对Arduino 1.5.4编译的:
void setup() {
// put your setup code here, to run once:
}
void loop() {
tone(1, 12345, 1000);
}
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)sketch_oct24a.ino: In function 'void loop()': sketch_oct24a:7: error: 'tone' was not declared in this scope
由于我有Arduino Due,因此我只能使用Arduino 1.5.4。
如何实现Due 的tone()和noTone() …