单击按钮时如何调用 javascript 函数? [英] How do I call a javascript function when a button is clicked?

查看:55
本文介绍了单击按钮时如何调用 javascript 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在使用:

<%=button_to_function "✓", checkButton(), :class => "buttonGrey"%>

但是 javascript 函数需要向它传递一些东西,以便它可以切换类(我希望在按下按钮时更改按钮类)我将传递什么作为参数来表示按钮?

But the javascript function needs something to be passed to it so it can toggle the class( I want the buttons class to be changed upon pressing it) What would I pass as a param to represent the button?

推荐答案

可以直接在button_to_function中执行javascript.

You can execute javascript directly in the button_to_function.

就你而言:

<%= button_to_function "✓", '$(this).toggleClass("buttonGrey buttonGreen");', :class =>"buttonGrey" %>

希望这会有所帮助!

这篇关于单击按钮时如何调用 javascript 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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