Why does my event handler raise a "not a function" error, but it works from the Firebug console?

Using jQuery 1.2.6, testing from Firefox 3 and IE7. I have a very simple JavaScript bit to reload a captcha image. In my JS file, I have:

var Captcha = {
    count: 0,

    Refresh: function(){
        // Concatenate "count" to force a URL change, which forces the browser to reload the image
        $('#Captcha').attr('src', 'Captcha.aspx?' + Captcha.count);
        Captcha.count++;
    }
}

My link is as follows:

<a href="javascript:void(0);" id="ChangeCaptcha" onclick="Captcha.Refresh();">Try a different image</a>

When I click on the link, I get a JavaScript error. From the Firebug plugin for Firefox, he says that โ€œCaptcha.Refreshโ€ is not a function. So, I go to my Firebug console in the same window and type

Captcha

And I get the "object" in the response line (as expected). Then i type

Captcah.Refresh

And I get the function () in the response line (as expected). Then i type

Captcha.Refresh()

, captcha, . , . Capcha.Refresh() , , . ? , JS , ?

+3
2

- , Captcha . IE id. FF ... , IE. click Captcha , .

:

Captcha.

, Captcha.

Pim Jager, , Captcha .

onclick :

onclick="window.Captcha.Refresh();"

... Captcha , .

( IE6 FF3 - Pim Jager)

+11

HTML javascript:

$('#ChangeCaptcha').click(Captcha.Refresh);
+7

Source: https://habr.com/ru/post/1702996/


All Articles