Function not calling within an onclick event

后端 未结 6 1502
情歌与酒
情歌与酒 2020-12-08 14:29

I want to add some HTML to the end of every youtube link to open up the player in a litebox. This is my code so far:

$(document).ready(function() {
  var val         


        
6条回答
  •  自闭症患者
    2020-12-08 14:51

    The reason is that open_litebox() is declared inside the document.ready function, and therefore not accessible from a global scope.

    You can move the function outside of document.ready, or, modify the code to attach the onclick handler using jQuery (which references the function directly):

    var link = $(' ' ).click(function () {
       open_litebox('hi');
    });
    $(this).after(link);
    

提交回复
热议问题