2010-12-21 105 views
1

我有以下的html代码:如何替换的onclick函数调用我的函数调用

<td align="center" class="shuttleControl"> 
    <img src="/i/mydb/icons/shuttle_reload.png" onclick="g_Shuttlep_v61.reset();" alt="Reset" title="Reset"/> 
    <img src="/i/mydb/icons/shuttle_last.png" onclick="g_Shuttlep_v61.move_all();" alt="Move All" title="Move All"/> 
    <img src="/i/mydb/icons/shuttle_right.png" onclick="g_Shuttlep_v61.move();" alt="Move" title="Move" /> 
    <img src="/i/mydb/icons/shuttle_left.png" onclick="g_Shuttlep_v61.remove();" alt="Remove" title="Remove" /> 
    <img src="/i/mydb/icons/shuttle_first.png" onclick="g_Shuttlep_v61.remove_all();" alt="Remove All" title="Remove All" /> 

基于上面的代码,使用jQuery,我怎么可以代替所有上述的onclick调用而是使用我的JavaScript函数get_Count();

所以结果我后:

<td align="center" class="shuttleControl"> 
    <img src="/i/mydb/icons/shuttle_reload.png" onclick="get_Count();" alt="Reset" title="Reset"/> 
    <img src="/i/mydb/icons/shuttle_last.png" onclick=" get_Count();" alt="Move All" title="Move All"/> 
    <img src="/i/mydb/icons/shuttle_right.png" onclick=" get_Count();" alt="Move" title="Move" /> 
    <img src="/i/mydb/icons/shuttle_left.png" onclick=" get_Count();" alt="Remove" title="Remove" /> 
    <img src="/i/mydb/icons/shuttle_first.png" onclick=" get_Count();" alt="Remove All" title="Remove All" /> 
</td> 

希望有人可以帮助。

谢谢。

回答

5

我会这样说:

$('img').unbind('click').click(get_Count); 

编辑:

嗯,我想这一点,这是行不通的。什么工作是.attr('onclick', '')。那么,这样做:

$('.shuttleControl img').attr('onclick', '').click(get_Count); 
+0

@Spiny,我的代码中还有其他img标签,所以我怎样才能确保我只引用了ShuttleControl类? – tonyf 2010-12-21 23:12:27

+0

`.unbind()`用于jQuery处理程序。 – user113716 2010-12-21 23:16:06

0

如果你没有在g_Shuttlep_v61需要这些功能在所有的,你可以只覆盖它们。

g_Shuttlep_v61.reset = 
g_Shuttlep_v61.move_all = 
g_Shuttlep_v61.move = 
g_Shuttlep_v61.remove = 
g_Shuttlep_v61.remove_all = get_Count; 

那么就没有必要乱用内联属性。