javascript - 函数语句需要 JQuery 中的名称错误

标签 javascript jquery

我有这个函数,但它给了我函数语句 require name onStop function

<script type="text/javascript">
 jQuery( function($) {
    $('#Hnav, #Nnav').NestedSortable(
            {
                accept: 'sort',
                noNestingClass: "no-children",
                helperclass: 'helper',
                autoScroll: true,
                onChange: function(serialized) {
                onStop : function(){
                    $('#output').html($(this).id);
                },
                    nestingPxSpace : '0'
            }
    );
});
</script>

最佳答案

在此上下文中,this 指的是发生 onStop 事件的 DOM 元素。 DOM 元素不是 jQuery 对象。

jQuery $(this) 对象没有 id 属性,而 DOM 元素有。因此,请使用:

$('#output').html(this.id);

或:

$('#output').html($(this).attr("id"));

并且不要忘记在 onChange 处理函数中关闭括号。

关于javascript - 函数语句需要 JQuery 中的名称错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11242212/

相关文章:

javascript - JS 使用类和超时创建闪烁?

javascript - 一页上多个表的数据表各自具有不同的 td 计数

javascript - 选择 1 更新选择 2,但选择 2 不触发

javascript - Angular SPA 应用程序使其他 URL 仍然具有基于 URL 编号的高亮导航栏部分

jquery - 如何切换语义 UI 按钮中的内容?

jquery - 将剑道图表转换为 pdf 时,它会在 pdf 图表上绘制线条

javascript - 当另一个日期发生更改时,JQuery UI Datepicker 重新启动

javascript - 文本框事件 JavaScript

javascript - 通过 AJAX 发送 jquery 字符串并使用 PHP 将其保存到 html 文件

javascript 解析 <a href> 链接中的文本