pwp*_*pwp 8 javascript function-calls
我想知道为什么,只要页面加载,btw_bijtellen ()
就会调用该函数.我想通过点击来调用它...
var $ = function (id) {
return document.getElementById (id);
}
function btw_bijtellen () {
window.alert("we want to calculate something after clicking th button");
}
$("bereken").onclick = btw_bijtellen ();
Run Code Online (Sandbox Code Playgroud)
Llo*_*oyd 16
你添加了()
哪个导致函数执行.
例如:
var myFunc1 = function() {
alert('Hello');
}(); // <--- () causes self execution
var myFunc2 = function() {
return 5 + 5;
};
var some_value = myFunc2(); // <--- Again () causes execution (you'd expect this one)
Run Code Online (Sandbox Code Playgroud)
在你的情况下,正如评论中提到的,你基本上是告诉onclick
将其值设置为函数的返回值.
如果你丢弃()
它应该按预期运行.
归档时间: |
|
查看次数: |
13905 次 |
最近记录: |