我想知道当我们用圆括号()和不用括号()调用函数时有什么区别。假设,如果我有像调用函数与()和无()之间的区别是什么。当我们将函数分配给变量时?
function($) {
var hideAnswers = function() {
$('#faqGrid tr td').each(function(){
var $td = $(this);
$td.children('div .answer').hide();
}); //end of $('#faqGrid tr td').each(fn)
}; //end of var hideAnswers = function() {}
var showMessage = function(message){
alert(message);
}; //end of var showMessage = function(){}
hideAnswers(); //working
hideAnswers; // not working
}(jQuery); // end of function($) {
第二个hideAnswers的功能;现在在这种情况下工作。另外,我想问我们什么时候分配函数给变量,什么时候没有?
也想,如果我有一个按钮,在点击其中我想调用这个函数,那么我们如何可以调用它就像
<input type="button" onclick = hideAnswers(); /> // is it right?
如果我也想值传递给这个函数是什么我xhtml页面。像
<input type="button" onclick = showMessage("what is your name "); /> // is it right?
感谢
尝试,并问一个问题,在一个时间。 SO不适用于洗衣清单=)。 – mrtsherman