我有一个JavaScript函数,例如函数:运行时元素显示
function SuperTD(id,str,tooltip) {
return '<td id="' +id+ '" title="' +tooltip+ '">' +str+ '</td>';
}
的SuperTD
打来电话,与许多元素连接在一起,而我不想改变它是如何工作(进不产生元素使用html字符串)。
,我需要触发时元素呈现的功能,例如:
function SuperTD(id,str,tooltip) {
var onwhat = 'onwhat="executeFixedFunction(' + "'" +id+ "'" + ')"';
return '<td><div id="' +id+ '" title="' +tooltip+ '" ' +onwhat+ '>' +str+ '</div></td>';
}
其中executeFixedFunction
是:
function executeFixedFunction(id) {
$('#' + id).uploadFile({
url:"/file/upload"
});
}
怎样才是正确的情况下做到这一点?我需要初始化一个file-upload元素无处不在SuperTD
叫
用户仍在使用Firefox 3.5。
编辑多个方面:
GridBuilder.render = function() {
// return from cache
var html = '';
// calls html += SuperTD(...)
return html;
}
GridBuilder.renderTo = function(id) {
$('#'+id).html(this.render());
// I guess this is where I should initialize the file upload, but still, is there another way?
}
您可以使用['MutationObserver'](https://developer.mozilla.org/en/docs/Web/API/MutationObserver),但它非常复杂。我建议你改变你的函数SuperTD来启动文件上传(这更有意义),而不是使用观察者。 – DontVoteMeDown
https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events –
或者,您可以将回调参数添加到函数定义中。 '函数(id,str,tooltip,callback){callback();}' –