在.bind单击处理程序中调用的jQuery函数正在文档就绪上运行 [英] jQuery function called in a .bind click handler is running on document ready

查看:72
本文介绍了在.bind单击处理程序中调用的jQuery函数正在文档就绪上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了一个简单的函数,并使用.bind()将click处理程序附加到链接。

I defined a simple function and attached a "click" handler to a link using .bind().

该函数在点击时没有运行 - 相反,它正在准备好文件。不知道为什么会发生这种情况。

The function is not running on click - rather, it is running on document ready. Not sure why this is happening.

我正在使用jQuery 1.3.2。

I am using jQuery 1.3.2.

HTML

<a href="#">click me</a>

jQuery

$(document).ready(function(){
  leftTurn = function($message){
    alert ($message);        
  };

  $('a').bind('click', leftTurn('hello'));
});

代码也是这里是一个JSFiddle

推荐答案

我想你可能想要使用回调/ bind的处理程序:

I think you may want to use the callback/handler of bind:

$('a').bind('click', function(){
    leftTurn();    
});

演示

来自 docs

 .bind( eventType, [ eventData ], handler(eventObject) )

这篇关于在.bind单击处理程序中调用的jQuery函数正在文档就绪上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆