简体   繁体   中英

No function call onClick

I have an object with a function inside of it but i can't get the function to execute on click

This is the fiddle https://jsfiddle.net/tgxu7rpv/23/

and this is the code

$(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>');

      });
});

I can't call the function onClick="MyObject.ae(this.id);"

This issue is a result of one of the default settings in JSFiddle.

You'll need to change one of the javascript settings.

Change the LOAD TYPE setting from:

在此处输入图片说明

to:

在此处输入图片说明

And that should do the trick!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM