Javascript onclick按钮不工作
我正在写一个基于facebook的chrome插件。但是,我创建的按钮无法加载posttoDB函数。posttoDB函数应该放在哪里?我试着把它放在a_facebook的课堂上和课堂外,两者都不起作用 让我困惑的是,如果我使用chrome开发工具并键入以下内容,它就会工作Javascript onclick按钮不工作,javascript,google-chrome,Javascript,Google Chrome,我正在写一个基于facebook的chrome插件。但是,我创建的按钮无法加载posttoDB函数。posttoDB函数应该放在哪里?我试着把它放在a_facebook的课堂上和课堂外,两者都不起作用 让我困惑的是,如果我使用chrome开发工具并键入以下内容,它就会工作 function posttoDB(i,index) { alert(i); } 有人能告诉我这个onclick函数应该放在哪里,函数应该是什么格式吗 var a_facebook = { wall_len
function posttoDB(i,index)
{
alert(i);
}
有人能告诉我这个onclick函数应该放在哪里,函数应该是什么格式吗
var a_facebook = {
wall_length: 0,
profile_length: 0,
listener_func: null,
u1: null,
array:null,
lang: {
post_placeholder: 'Type your anonymous post...',
post_add: 'Send'
},
create: function(){
this.initPage();
//myFunction(1,2);
},
initPage: function(){
var i=0;
clearInterval(a_facebook.listener_func);
this.listener_fu=setInterval(function(){
elements=document.getElementsByClassName("_5jmm _5pat _5uch");
select_text="";
for(i=0;i<array.length;i++)
{
select_text+="<option value=>";
//select_text+="\"+"\">";
select_text+=array[i];
select_text+="</option>";
}
for(i=0;i<elements.length;i++)
{
var exist_name="submit"+i;
var exist_button = document.getElementById(exist_name);
if (exist_button!=null)
continue;
var a=elements[i].getElementsByClassName("uiUfi UFIContainer _5pc9");
if(a.length!=0)
{
var button_id="submit"+i;
var button=document.getElementById(button_id);
mydata=JSON.parse(elements[i].dataset['ft']);
var post_id=mydata['mf_story_key'];
var button_text="<button type=\"button\" onclick=\"posttoDB(";
button_text+=i;
button_text+=",";
button_text+=post_id;
button_text+=")\" id= \"";
button_text+=button_id;
button_text+="\">send</button>";
if(button==null)
a[0].innerHTML+=button_text;
}
}
}
,1000);
},
posttoDB: function(index,post_id)
{
alert(i);
}
};
a_facebook.create();
您是否尝试过代替.innerHTML+=按钮\文本在字符串变量中预先收集HTML,然后执行.innerHTML=变量?