Firebug:TypeError:在没有实现接口HTMLElement的对象上调用'click'

时间:2014-02-25 12:53:05

标签: javascript php jquery html

当我点击带有ID"#123"的按钮时,我收到此错误 - 我不知道原因是什么。

我的PHP文件中的代码:

$("#123").click(function(){
    getCheckedValues('oberpunkte', 'input:checkbox[class=oberpunkte]:checked', 'input[type=textfield]');
    getCheckedValues('unterpunkte', 'input:checkbox[class=unterpunkte]:checked', 'input[type=textfield]');
    ajaxCheckedValues('POST', 'selected.php', '#sumadd');
});

上面代码的我的JS函数:

function getCheckedValues(arrayname, selector, nextselector){
    var array = arrayname;
    array = new Array();
    $(selector).each(function(){
        array.push($(this).next(nextselector).val());
    });
}

function ajaxCheckedValues(type, url, div){

    var kategorie = ($("input:radio:checked[name='kategorie']").attr('class'));

    $.ajax({
        type: type,
        url: url,
        data: { oberpunkte : oberpunkte, unterpunkte : unterpunkte, kategorie : kategorie },
        success: function (data)
                               {
                                console.log(data);
                                $(div).html(data);
                               }
          });
 }

Firebug错误:

enter image description here

我也警告过#34; kategorie" - 它不是空的。有什么想法吗?

Button和DIV的HTML / PHP:

echo("<input type='button' name='test' id='123' value='Checklist speichern'/>");

echo("<div id='sumadd' value=''></div>");

编辑注意:添加了HTML / PHP

1 个答案:

答案 0 :(得分:3)

我想这个问题是因为你在ajax调用中对oberpunkte和unterpunkte进行了未定义。试试这个

$("#Button123").click(function(){
  var  oberpunkte=[], unterpunkte=[];
 getCheckedValues(oberpunkte, 'input:checkbox[class=oberpunkte]:checked', 'input[type=textfield]');
    getCheckedValues(unterpunkte, 'input:checkbox[class=unterpunkte]:checked', 'input[type=textfield]');
    ajaxCheckedValues('POST', 'selected.php', '#sumadd',oberpunkte,unterpunkte);
});


function getCheckedValues(array, selector, nextselector){
    $(selector).each(function(){
        array.push($(this).next(nextselector).val());
    });
}


function ajaxCheckedValues(type, url, div,oberpunkte,unterpunkte){

    var kategorie = ($("input:radio:checked[name='kategorie']").attr('class'));

    $.ajax({
        type: type,
        url: url,
        data: { oberpunkte : oberpunkte, unterpunkte : unterpunkte, kategorie : kategorie },
        success: function (data)
                               {
                                console.log(data);
                                $(div).html(data);
                               }
          });
 }

同时更改输入字段的ID。 Id必须以字母开头。
校验 What are valid values for the id attribute in HTML?