javascript - Firebug : TypeError: 'click' called on an object that does not implement interface HTMLElement

标签 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

我还提醒了“kategorie”——它不是空的。有什么想法吗?

Button 和 DIV 的 HTML/PHP:

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

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

编辑注意:添加了 HTML/PHP

最佳答案

我想这个问题是因为您在 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?

关于javascript - Firebug : TypeError: 'click' called on an object that does not implement interface HTMLElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22014808/

相关文章:

javascript - 在 bootstrap col 下方打开新的 div

php - 通过合并PHP和MySql覆盖的条件是否有利于减少DB调用次数

javascript - 为什么jQuery或诸如getElementById之类的DOM方法找不到元素?

javascript - 将带有 HTML 实体的字符串作为 prop 传递,未在 Material UI 中正确呈现

javascript - 使用 JavaScript 和 servlet 下载文件

php - magento 2.x 中 magento 1.x 模型的等效项是什么

javascript - Angular js 过滤器不适用于某些移动设备

javascript - 页面底部的滚动条

javascript - 无法将默认值绑定(bind)到 knockoutJS 中的下拉菜单

php-cgi.exe 在恰好 500 次点击后退出