我是否有办法从预先输入范围外部访问更新程序功能?
我当前的例子是在updater函数中,我有一些自定义逻辑创建一些html并将其附加到正文,例如使用以下代码段示例:
updater: function(item){
$input = $('<span/>',{
class:'label label-info',
text:item,
style:'margin-left:4px'
});
...
$('#tagContainer').append($input);
}
现在我的问题是:我是否可以将此功能链接到按钮,以便在单击按钮时触发它,考虑到我将传递'item'参数?
我想这个问题涉及到功能范围,这是我的知识缺乏的地方,需要一些见解。
答案 0 :(得分:2)
将其定义为单独的函数:
function appendInput(item) {
//same contents
}
update: appendInput ...
$("button").on('click', function () { appendInput(this); });