Javascript 在渲染元素时运行函数
我有一个javascript函数,例如:Javascript 在渲染元素时运行函数,javascript,jquery,Javascript,Jquery,我有一个javascript函数,例如: function SuperTD(id,str,tooltip) { return '<td id="' +id+ '" title="' +tooltip+ '">' +str+ '</td>'; } function SuperTD(id,str,tooltip) { var onwhat = 'onwhat="executeFixedFunction(' + "'" +id+ "'" + ')"'; retu
function SuperTD(id,str,tooltip) {
return '<td id="' +id+ '" title="' +tooltip+ '">' +str+ '</td>';
}
function SuperTD(id,str,tooltip) {
var onwhat = 'onwhat="executeFixedFunction(' + "'" +id+ "'" + ')"';
return '<td><div id="' +id+ '" title="' +tooltip+ '" ' +onwhat+ '>' +str+ '</div></td>';
}
其中executeFixedFunction为:
正确的事件是什么?我需要初始化一个名为SuperTD的元素
用户仍在使用Firefox3.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?
}
您可以使用setTimeout函数延迟回调函数
function SuperTD(id,str,tooltip) {
var onwhat = 'onwhat="executeFixedFunction(' + "'" +id+ "'" + ')"';
setTimeout(function(){ executeFixedFunction(id) }, 1000);
return '<td><div id="' +id+ '" title="' +tooltip+ '" ' +onwhat+ '>' +str+ '</div></td>';
}
您可以使用setTimeout函数延迟回调函数
function SuperTD(id,str,tooltip) {
var onwhat = 'onwhat="executeFixedFunction(' + "'" +id+ "'" + ')"';
setTimeout(function(){ executeFixedFunction(id) }, 1000);
return '<td><div id="' +id+ '" title="' +tooltip+ '" ' +onwhat+ '>' +str+ '</div></td>';
}
如果你已经使用jQuery,我会考虑这样做:
function superTD (id, str, tooltip) {
return $('<td/>', {
id: id,
title: tooltip,
text: str
}).uploadFile({
url: '/your-url'
})
}
您可以调用SuffTD上的AppDoto方法将其插入表行
如果您已经使用jQuery,我会考虑这样做:
function superTD (id, str, tooltip) {
return $('<td/>', {
id: id,
title: tooltip,
text: str
}).uploadFile({
url: '/your-url'
})
}
然后,您可以在superTD上调用appendTo方法,将其插入表行中所有内容以及稍微修改的Jakubs建议。再见
所有内容都与Jakubs的建议略有修改。再见
你可以用,但它很复杂。我建议您将函数SuperTD更改为初始化文件上载,这比使用观察者更有意义。或者,您可以将回调参数添加到函数定义中。functionid、str、tooltip、callback{callback;}这两种解决方案都不起作用,因为客户端仍然使用Firefox 3.5,我将编辑我的问题..所以使用@RuslanasBalūIūnas所说的回调。这是一个聪明的解决方案。你可以使用它,但它非常复杂。我建议您将函数SuperTD更改为初始化文件上载,这比使用观察者更有意义。或者,您可以将回调参数添加到函数定义中。functionid、str、tooltip、callback{callback;}这两种解决方案都不起作用,因为客户端仍然使用Firefox 3.5,我将编辑我的问题..所以使用@RuslanasBalūIūnas所说的回调。这是一个聪明的解决方案。这不可靠。这不可靠。