我試圖將「term」傳遞給外部函數。如何自動將jQuery函數參數傳遞給外部函數?
$('#item').terminal(function(command, term) {
我一直能夠做到這一點的唯一方法是通過在函數中傳遞「term」。
myfucntion(term, 'hello world');
有沒有一種方法,我可以做到這一點,而不必每次都通過它?
編輯:
$(function() {
$('#cmd').terminal(function (command, term) {
switch (command) {
case 'start':
cmdtxt(term, 'hello world');
break;
default:
term.echo('');
}
}, {
height: 200,
prompt: '@MQ: '
});
});
function cmdtxt(term, t) {
term.echo(t);
}
我不清楚你在做什麼。請提供更完整的示例。 – 2013-04-05 12:57:03
我加了我的完整代碼。正如你所看到的,我將外部函數傳遞給外部函數,可以稱之爲回聲函數。 – Shylor 2013-04-05 13:02:02