TypeError:单击调用未实现接口HtmlElement的对象

r3w*_*3wt 1 javascript jquery

我已经看到了关于这个主题的其他问题,但我无法在我的代码中发现错误.

$('#submit_bulk').on('click',function(e){

    var action = $('select[name="bulk_action"]'),
    targets = $('table tr td:first-child :checkbox:checked');
    if(action=='invalid' || targets.length == 0){
        sk.alert('Nothing to do','warning');
        return false;
    }else{
        $(this).html('Working....');

        var fData = {
            action: action,
            mixtapes: '',
            singles: ''
        };

        $.each(targets,function(i,v){
            if($(this).data('type') == 'mixtape'){
                fData.mixtapes += $(this).data('id')+',';
            }else{
                fData.singles += $(this).data('id')+',';
            }
        });

        fData = $.param(fData); 

        console.log(fData); //i get no output here. is fData null?

        $.post(window.location.origin+'/adminAPI/bulk_action',fData,function(data){
            var data = JSON.parse(data);
            if(data.error==0){
                sk.alert('Your changes were saved','success');
                //update view here.
            }else{
                sk.alert(data.message,'error');
            }
        });
        $(this).html('go');
    }

});
Run Code Online (Sandbox Code Playgroud)

r3w*_*3wt 5

说到明智的话.确保您没有将jQuery selector值作为值传递到表单数据中.

违规行是:

var action = $('select[name="bulk_action"]')

本来应该:

var action = $('select[name="bulk_action"]').val()