1

私はこの関数を持っていますが、それは私に function statement 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>
4

3 に答える 3

4

このコンテキストでは、イベントが発生thisする DOM 要素を指します。onStopDOM 要素は jQuery オブジェクトではありません。

jQuery$(this)オブジェクトにはプロパティがありませんがid、DOM 要素にはプロパティがあります。したがって、次のいずれかを使用します。

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

また:

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

onChangeそして、ハンドラー関数でブラケットを閉じることを忘れないでください。

于 2012-06-28T10:04:18.817 に答える
1

角かっこがありませんでした。間違った構文を使用して ID を取得しています。これを試してください。

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

する必要があります

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

また

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

  jQuery(function($) {
    $('#Hnav, #Nnav').NestedSortable({
        accept: 'sort',
        noNestingClass: "no-children",
        helperclass: 'helper',
        autoScroll: true,
        onChange: function(serialized) {
            alert("changed");// Changed to fix
        },               
        onStop: function() {
             $('#output').html(this.id);
        },
        nestingPxSpace: '0'       
    });
});​
于 2012-06-28T10:03:50.133 に答える
1

まとめると、コードには 2 つの問題があります。

  1. 内部関数が正しく閉じられていませんでした。
  2. jQuery セレクターでサポートされていない要素の id プロパティを使用しました。

変更されたコードは、

jQuery( function($) {
    $('#Hnav, #Nnav').NestedSortable(
            {
                accept: 'sort',
                noNestingClass: "no-children",
                helperclass: 'helper',
                autoScroll: true,
                onChange: function(serialized) {
                    //A empty function
                },
                onStop : function(){
                    $('#output').html($(this).attr("id"));
                },
                nestingPxSpace : '0'
            }
    );
});
于 2012-06-28T10:20:50.307 に答える