2012-08-30 40 views
-1

我不知道正确的方法来传递点击函数的事件参数。点击函数的事件参数[JQuery]

所以我不能传递路线:

http://www.codecademy.com/courses/you-and-jquery/0?curriculum_id=4fc3018f74258b0003001f0f#!/exercises/4

谁能帮我?

UPDATE:

我的回答是像下面,但它仍然不正确。

function addBarClickEvent($bar,value) { 
    $bar.click(
     function(e) { 
      alert(value); 
     } 
    ); 
} 
+0

阅读文档:http://api.jquery.com/click –

+0

@MattBall:你能帮我吗? –

+0

控制台中是否有任何javascript错误? – karthikr

回答

2

事件参数的点击功能通过如下

$(element).click(function(event){ // <-- see event argument getting passed in 
    // now you can use event object here 
}); 

编辑

这是怎样的代码开始

function addBarClickEvent($bar,value) { 
    // add a click event to the bar that 
    // pops up an alert with the bars value 
    $bar.click(
     // your code goes here! 
    ); 
} 

这是怎么了我的代码看起来像功能

012里面
function addBarClickEvent($bar,value) { 
    // add a click event to the bar that 
    // pops up an alert with the bars value 
    $bar.click(
     function(e){alert(value);} 
    ); 
} 

尽管我刚刚测试过,并且其他方式也能正常工作。尝试重置并键入它

+0

我已更新我的问题。但我无法通过课程。 –

+0

在这里工作正常http://www.codecademy.com/courses/you-and-jquery/0?curriculum_id=4fc3018f74258b0003001f0f#!/exercises/4 –

+0

我猜你必须在一行写所有内容?不知道该应用程序的工作原理..但这就是我所做的,它在我的问题中运行良好 –