0

button.enter-matchいくつかの要素を持つ長いテーブルの最後で実行される次のコードがあります。

$("button.enter-match")
.button()
.on('click', function() {
    $("form.enter-match").dialog({
        modal: true,
        height: 'auto',
        width: 200,
        close: function() {
            $("form.enter-match input[name='code']").val('');
        },
        open: function() {
            $("form.enter-match input[name='code']").val('').focus();
        },
        buttons: {
            Set: function() {
                pid = $(this).parents("[data-pid]").data('pid');

                if ($("form.enter-match input[name='code']").val() == '') {
                    alert('Code empty!');

                    return false;
                }

                $.post(
                    request_url,
                    {
                        'action': 'set_match',
                        'pid': pid,
                        'code': $("form.enter-match input[name='code']").val()
                    },
                    function (data) {
                        error_handler(data);

                        if (data['error'] == null) {
                            $("tr#pid-" + pid + " td.code:first div").html('<i>' + $("form.enter-match input[name='code']").val() + '</i>');
                            $("form.enter-match").dialog('close');
                        }
                    },
                    'json'
                );
            }
        }
    });
});

この行は、必要に応じてコードで再利用するためにドキュメントの一番上に作成されるため、データ値pid = $(this).parents("[data-pid]").data('pid');を取得しません。したがって、この属性を持つ親は存在しませんが、存在します。コードの一部からこの特定の値を取得するにはどうすればよいですか?pidform#enter_match[data-pid]button.enter-match[data-pid]button.enter-match$("form.enter-match").dialog()

4

1 に答える 1