Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法通过javascript中动态创建的复选框的检查操作创建表行_Javascript_Html - Fatal编程技术网

无法通过javascript中动态创建的复选框的检查操作创建表行

无法通过javascript中动态创建的复选框的检查操作创建表行,javascript,html,Javascript,Html,我试图在动态创建的复选框的检查操作上创建一行表。流未进入检查事件的函数 addCheckboxItems : function(form){ var newBox = ('<input type="checkbox" name="checkBoxItem" onCheck="JavaScript:addRowItems(this)"; id="checkBoxItemId" value="' + form.combobox.value +'"'+ '>'+form.combo

我试图在动态创建的复选框的检查操作上创建一行表。流未进入检查事件的函数

addCheckboxItems : function(form){
    var newBox = ('<input type="checkbox" name="checkBoxItem" onCheck="JavaScript:addRowItems(this)"; id="checkBoxItemId" value="' + form.combobox.value +'"'+ '>'+form.combobox.value);
    document.getElementById("divCheckbox").innerHTML = newBox;

    }
    addRowItems : function(element){
    alert('Hi');
    if(document.getElementById("checkBoxItemId").checked){
        var tableRef =  document.getElementById('tbl').getElementsByTagName('tbody')[0];
        var newRow   = tableRef.insertRow(tableRef.rows.length);
        var td1 = document.createElement("td")
        var strHtml1 = document.getElementById('checkBoxItemId').value;
        td1.innerHTML = strHtml1.replace(/!count!/g,count);

        var td2 = document.createElement("td")
        var strHtml2 = "NA";
        td2.innerHTML = strHtml2.replace(/!count!/g,count);

        var td3 = document.createElement("td")
        var strHtml3 = "<a>Remove</a>";
        td3.innerHTML = strHtml3.replace(/!count!/g,count);

        newRow.appendChild(td1);
        newRow.appendChild(td2);
        newRow.appendChild(td3);

        tableRef.appendChild(newRow);
    }
}
addCheckboxItems:函数(表单){
var newBox=(“”+form.combobox.value);
document.getElementById(“divCheckbox”).innerHTML=newBox;
}
addRowItems:函数(元素){
警报(“Hi”);
if(document.getElementById(“checkBoxItemId”).checked){
var tableRef=document.getElementById('tbl').getElementsByTagName('tbody')[0];
var newRow=tableRef.insertRow(tableRef.rows.length);
var td1=document.createElement(“td”)
var strHtml1=document.getElementById('checkBoxItemId')。值;
td1.innerHTML=strHtml1.replace(/!count!/g,count);
var td2=document.createElement(“td”)
var strHtml2=“NA”;
td2.innerHTML=strHtml2.replace(/!count!/g,count);
var td3=document.createElement(“td”)
var strHtml3=“删除”;
td3.innerHTML=strHtml3.replace(/!count!/g,count);
newRow.appendChild(td1);
newRow.appendChild(td2);
newRow.appendChild(td3);
tableRef.appendChild(纽罗);
}
}

如何实现这一点…提前感谢..

首先,您的语法告诉我们,您在某些对象中创建函数
addCheckboxItems:function(form)
,但在html事件处理程序中
onCheck
搜索函数的全局范围。因此,您应该在全局范围内定义函数,如
addCheckboxItems=function(form)

此外,没有
oncheck
事件。有
onclick
事件


这里有一个带有这些更正的示例,您可以从中了解(并调试)我所说的内容。但是,它在
addRowItems
中崩溃,因为代码中没有足够的上下文来构建一个工作应用程序。。。但是您已经运行了处理程序,现在可以继续运行了。

您好,在您的函数中,您可以试试这个吗

addCheckboxItems : function(form){
var newBox = ('<input type="checkbox" name="checkBoxItem"
onchange="JavaScript:addRowItems(this)"; 
id="checkBoxItemId" value="' + form.combobox.value +'"'+
 '>'+form.combobox.value);
 document.getElementById("divCheckbox").innerHTML = newBox;

}
addCheckboxItems:函数(表单){
var newBox=(“”+form.combobox.value);
document.getElementById(“divCheckbox”).innerHTML=newBox;
}
我添加了
input
元素的
onchange
事件。这应该能奏效

编辑


您还可以尝试使用
复选框的
onclick
事件。似乎
更改
事件在IE中的行为有所不同,因此许多用户更喜欢
单击
事件,该事件在
输入
元素的状态发生更改后触发。你可以参考

我真的不明白问题的第一行,请编辑或创建一个你当前的代码为什么Java标记?我在这里没有看到任何Java。