这是问题“<a href="https://stackoverflow.com/questions/14920322/jquery-output-to-console-sum-of-2-variables">jQuery output to console sum of 2 variables'的扩展.
我有以下功能:
function printSum() {
console.log('Sum:' + (c.getBehaviour() + t.getBehaviour()));
}
并希望根据printSum()
click 函数中的值加载 HTML,如下所示:
$('#surname-help-label').click(function(e) {
var helpText = $('#surname-help-text').html('loading…');
if (printSum() >= 25) {
helpText.load('help-text.html div:nth-of-type(2)');
} else {
helpText.load('help-text.html div:first');
console.log('what do you get:' + printSum());
};
e.preventDefault();
});
我在该行中添加了console.log('what do you get:' + printSum());
用于调试的目的,它返回的值undefined
意味着该else {}
块总是被调用。我该如何补救?