Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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 与DOM元素斗争_Javascript_Html_Dom - Fatal编程技术网

Javascript 与DOM元素斗争

Javascript 与DOM元素斗争,javascript,html,dom,Javascript,Html,Dom,我的.aspx页面中有一个html表,如下所示: <table id="quotationsListTable" class="quoteTbl" width="100%" border="1"> <tr> <th></th> <th>REF</th> <th>Name</th> <th>Arrival</th> <th&g

我的.aspx页面中有一个html表,如下所示:

  <table id="quotationsListTable" class="quoteTbl" width="100%" border="1">
  <tr>
    <th></th>
    <th>REF</th>
    <th>Name</th>
    <th>Arrival</th>
    <th>Time</th>
    <th>Departure</th>
    <th>Time</th>
    <th>Curr</th>
    <th>Sale</th>
    <th>Cost</th>
  </tr>
  <tr>
    <td><input type="checkbox" name="chk"/></td>
    <td> 1 </td>
    <td><input type="text" style="width: 50px" /> </td>
    <td><input type="text" style="width: 150px"/> </td>
    <td> <input type="text" style="width: 50px"/> </td>
    <td> <input type="text" style="width: 50px"/> </td>
    <td> <input type="text" style="width: 50px"/> </td>
    <td> <input type="text" style="width: 50px"/> </td>
    <td> <input type="text" style="width: 50px"/> </td>
    <td> <input type="text" style="width: 50px"/> </td>
  </tr>
  </table>

裁判
名称
进站
时间
离开
时间
咖喱
特价
成本
1.
我还有一个javascript函数,用于删除表中的所有行,调用by元素ID“quotationsListTable”

位于单独的.js文件中的javascript函数如下所示:

deleteAllrows('quotationsListTable');

function deleteAllrows(tableID) {
    try {
        var table = document.getElementByID(tableID);
        var rowCount = table.rows.length;

        for (var i = 1; i < rowCount; i++) {
            var row = table.rows[i];
            var chkbox = row.cells[0].childNodes[0];
            table.deleteRow(i);
            rowCount--;
            i--;


        }
    } catch (e) {
        alert(e);
    }
}
deleteAllrows('quotationsListTable');
函数deleteAllrows(tableID){
试一试{
var table=document.getElementByID(tableID);
var rowCount=table.rows.length;
对于(变量i=1;i

目前的问题是,我的js函数无法按id检索表,抛出的错误消息是“未定义”。

这是
文档。getElementById
注意小的
d

var table = document.getElementById(tableID);

这是
文档。getElementById
注意小的
d

var table = document.getElementById(tableID);

您应该在页面内容准备好后设置功能。 请将您的“getElementByID”更改为“getElementByID”,D um小写。 尝试使用jQuery,这是一种简单的方法

见:


$().ready(函数(){
删除所有行();
函数deleteAllrows(){
试一试{
var table=document.getElementById('quotationsListTable');
警报(表);
var rowCount=table.rows.length;
对于(变量i=1;i
您应该在页面内容准备好后设置功能。 请将您的“getElementByID”更改为“getElementByID”,D um小写。 尝试使用jQuery,这是一种简单的方法

见:


$().ready(函数(){
删除所有行();
函数deleteAllrows(){
试一试{
var table=document.getElementById('quotationsListTable');
警报(表);
var rowCount=table.rows.length;
对于(变量i=1;i
我建议您包括jquery库,并用单行删除行。。检查这把小提琴


我建议您包括jquery库并删除单行的行。。检查这把小提琴


不要使用
alert()
进行调试;完全删除try..catch并查看。要删除所有行,实际上只需设置其innerHTML=“”;不要使用
alert()
进行调试;完全删除try..catch并查看。要删除所有行,实际上只需设置其innerHTML=“”;
deleteAllrows('quotationsListTable');

function deleteAllrows(tableID) {
   $("#"+tableID+"tr:gt(0)").remove()
}