开发者

Jquery weird behavior - object.click

开发者 https://www.devze.com 2023-02-25 06:53 出处:网络
Please take a look on this code: <!DOCTYPE html> <html lang=\"es\"> <head runat=\"server\">

Please take a look on this code:

    <!DOCTYPE html>
<html lang="es">
<head runat="server">
    <title>Main - Annex7</title>
    <meta charset="utf-8" />
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(load);

        function load() {
            var objectX= $("#objectX")
            objectX.click(alert('auch'));
        }
    </script>

Should not the 'click' event get fired when I do click on objectX??? B开发者_StackOverflow社区ut this alert is fired when I load the document...

I´m a little confused, please any help would be very well received.

Thanks in advance...


change the click event to:

objectX.click(function(){
    alert('auch');
});

you need to pass a function into the event,
if you just pass an action you will get errors


You need to wrap it in a function, such as an anonymous one...

objectX.click(function() { alert('auch'); });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号