如何将匿名函数转换为常规函数?
这里完全是 JS 菜鸟。我有以下行实现 jQuery Slider:
<script type="text/javascript">
$(document).ready(function () {
$("#wheelLeft").slider({
orientation: 'vertical', value: 37,
min: -100, max: 100,
slide: function (event, ui) { $("#lblInfo").text("left"); } });
});
</script>
基本上在 slide
事件中,#lblInfo
将其文本设置为 left
。这很好用。但是,我想将处理幻灯片事件的内联匿名函数转换为常规函数。
有人可以帮忙吗?
Total JS noob here. I have the following line that implements the jQuery Slider:
<script type="text/javascript">
$(document).ready(function () {
$("#wheelLeft").slider({
orientation: 'vertical', value: 37,
min: -100, max: 100,
slide: function (event, ui) { $("#lblInfo").text("left"); } });
});
</script>
Basically on the slide
event, the #lblInfo
gets its text set to left
. This works fine. However, I'd like to convert the inline anonymous function that handles the slide event into a regular function.
Can someone help out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
会做的。这显然不是一个理想的解决方案,因为它仍然使用匿名,但应该解决您需要手动操作该函数的任何问题
would do it. It's obviously not an ideal solution as it still uses the anonymous but should solve any issues you have where you need to manipulate the function manually
只需定义一个命名函数:
Just define a named function: