javascript - 元素、事件、ui 变量是什么意思? - jQuery(用户界面)

标签 javascript jquery jquery-ui

例如:( http://api.jqueryui.com/sortable/ )

$( ".selector" ).sortable({
    deactivate: function( event, ui ) {}
});

很多 jQuery API 函数描述都有这类参数。 它们有多种格式:el、element、elem、ev、event、ui 等。 有人可以向我解释如何解释这个吗?我测试了上面的函数,它似乎不需要任何这个输入?

最佳答案

它们是参数。您可以随意命名它们:

function myFunc(a){
    alert(a);
}

myFunc("Hello");

等同于:

function myFunc(whatever){
    alert(whatever);
}

myFunc("Hello");

此外,由于 javascript 不是强类型的,因此您不需要使用正确数量的参数来调用函数:

function fourArgs(a, b, c, d){
}

function oneArg(a){
}

fourArg("Hello"); // a will be the string 'Hello', b c and d will be undefined

oneArg("Hello", 1, 2, 3); // a will be the string 'Hello', the other values are not referenced (they can still be accessed through arguments)

因此,您创建一个函数并将其传递给 jQuery 以将其用作回调。 jQuery 将始终使用文档中指定的参数来调用它。是否命名要在您创建的函数中使用的参数取决于您。如果您不想使用它们,可以省略它。

关于javascript - 元素、事件、ui 变量是什么意思? - jQuery(用户界面),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32769871/

相关文章:

javascript - 使用 jQuery,如何获取图像以全屏打开浏览器的高度和宽度?

jquery - 从 Popover 中移除阴影

javascript - 图像不会使用 Javascript Image Slider 滑动

javascript - 检查父 iFrame 是否已加载 jQuery

javascript - ExtJS 存储,无法将数据加载到网格

javascript - 如何在单击 li 元素后更改其背景?

javascript - 没有 jQuery UI(或根本没有 jQuery?)的可排序/可拖动列表项

javascript - 创建构建时,我的应用程序会上传到 expo 吗?

jquery - 延迟后使用 jQuery 添加一个类

javascript - 如何使用正则表达式替换 <li>anything</li> 中的 "i"