2016-10-09 41 views
0

我有一个对象与功能的它里面,但我不能得到的函数,在点击执行没有函数调用的onclick

这是小提琴https://jsfiddle.net/tgxu7rpv/23/

,这是代码

$(document).ready(function() { 
    MyObject = { 
     ae: function(clicked_id) { 
     var items = JSON.parse(localStorage.getItem('entry')); 
     if (items == null || typeof items !== 'object') { 
     items = []; 
     } 
     var entry = { 
     'num': clicked_id 
     }; 
    items.push(entry); 
    localStorage.setItem('entry', JSON.stringify(items)); 

    alert(localStorage.getItem('entry')); 

    var fromStorage = localStorage.getItem('entry'); 
    for (var data in fromStorage) { 
     alert("Value" + fromStorage[data]); 
     } 
    } 
    }; 

$(document).on('click', '.btn-primary', function(){ 

$('.table tbody').append('<tr class="child"><td>one</td><td><button id="num" onClick="MyObject.ae(this.id);" type="button" class="invite ">Invite</button></td></tr>'); 

     }); 
}); 

我不能调用函数onClick="MyObject.ae(this.id);"

+0

小提琴似乎很适合我,很多恼人的警报。它**工作的原因是因为你使用全局变量。 – adeneo

+0

好的,让我试试其他浏览器 –

回答

0

这个问题是在的jsfiddle默认设置一个的结果。

您需要更改其中一个javascript设置。

更改负载类型设置从:

enter image description here

到:

enter image description here

这应该做的伎俩!