使用 Jquery 将命名函数注册为侦听器
我是 javascript/jquery 的新手,并且在网上进行了一些探索,但我无法弄清楚为什么以下内容无效:
var toggleSection = function(sectionName) {
// Do some Jquery work to toggle stuff based on sectionName string
// (concatenate sectionName with other text to form selectors)
};
$('#togglecont1').click(toggleSection("container1"));
是否有一些明显的我遗漏的东西?提前致谢。
I'm new to javascript/jquery and I've done some poking around the web, but I can't figure out why the following is invalid:
var toggleSection = function(sectionName) {
// Do some Jquery work to toggle stuff based on sectionName string
// (concatenate sectionName with other text to form selectors)
};
$('#togglecont1').click(toggleSection("container1"));
Is there something obvious I'm missing? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试调用点击处理程序定义中的函数,但这是行不通的。你可以这样做:
Your trying to call the function inside the click handler definition, which won't work. you could do something like this: