我正在尝试调用包含动态变量作为参数的javascript函数。我认为我在语法上没有执行此特定功能。我尝试过几种组合,但似乎都没有。请有人建议..
for( i=0; i<succeedList.length; i++){
var file_uniq_id = succeedList[i].filename_uniq;
//Creating dynamic button
var subm_btn = document.createElement("INPUT");
subm_btn.setAttribute("onclick", "UploadMyScript.submitTitle(this.id,'+file_uniq_id+')");
p_titleBtn.appendChild(subm_btn);
}
UploadMyScript.submitTitle = function(id, uniqID){
// Does something ....
}
我的问题是我似乎无法将'file_uniq_id'值传递给UploadMyScript.submitTitle()。
答案 0 :(得分:4)
为什么不使用事件监听器?
subm_btn.addEventListener('click', function () {
UploadMyScript.submitTitle(subm_btn.id, file_uniq_id); },
false);