The Chrome extension popup is not working, click events are not handled

后端 未结 2 1864
北恋
北恋 2020-11-22 02:51

I have created a JavaScript variable and when I click on the button it should increment by 1, but its not happening.

Here\'s manifest.json.



        
2条回答
  •  时光说笑
    2020-11-22 03:23

    Change your onclick:

    onclick="count"
    

    Or change your count function to something like this:

    function count()
    {
    
        var demo = document.getElementById("demo");
        return function() {
            demo.innerHTML = ++a;
        }
    
    }
    

    Here is a nice demo I put together:

    Code (this assumes that you add id="the_button" to your button):

    window.onload = function () {
        var button = document.getElementById("the_button");
        button.onclick = count();
    
        function count() {
            var a = 0;
            var demo = document.getElementById("demo");
            return function () {
                demo.innerHTML = ++a;
            }
        }
    }
    

    Demo: http://jsfiddle.net/maniator/ck5Yz/

提交回复
热议问题