日期:2014-05-16  浏览次数:20401 次

js动态添加的行中td的样式不起作用
各位大虾会的就帮帮忙,在线等

在表格中原先有一行,动态添加的行中td的样式不起作用,是什么问题?
代码如下

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="MyKPIDetail4_T.aspx.vb" Inherits="MyKPIDetail4_T" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>在3的基础上删除delete改为删除选中行</title>
  <style type ="text/css" >
  .td0{background-color:White ;width:500px;}
  .td1{background-color:White ;width:80px;}
  .td2{background-color:White ;width:100px;}
  .td3{background-color:White ;width:200px;}
  .td4{background-color:White ;width:100px;}
  </style>
  <script language ="javascript" type ="text/javascript" >
  var linenum = 1;
  var strvalue;
  var strtext;
   
  function countWeight()
  {
  var WeightT = 0;
  for (var i=1 ;i<= linenum ;i++)
  {
  if (document .all["tb_line"+i].value == "" || document .all["tb_line"+i].value ==null)
  {

  }
  else 
  {
  var weight = parseInt(document .all["tb_line"+i].value);
  if(weight<=100 && weight >0)
  {
  WeightT += parseInt(document .all["tb_line"+i].value);
  }
  else
  {
  alert ("权重必须是0到100之间的数字!");
  }
  }
  }
  document .all["lb_weight"].innerHTML = WeightT ;
  };
  function delTR(obj)
  {
  var table = obj .parentNode.parentNode.parentNode;
  table .removeChild(obj .parentNode.parentNode);
  };
  function Add_tr()
  {
  if (linenum ==1)
  {
  getoption ();
  }  
  linenum =linenum +1;
  var tableobj = document .getElementById ("table1");
  var trobj = document .createElement ("tr");
  trobj .setAttribute ("id","tr"+linenum);

  // 添加td0
  var tdobj0 = document .createElement ("td");
  tdobj0 .setAttribute ("class","td0");
  var textareaobj0 = document .createElement ("textarea");
  textareaobj0.setAttribute ("id","ta_line"+linenum );
  textareaobj0.setAttribute ("name","ta_line"+linenum );
  textareaobj0 .setAttribute ("cols","35");
  textareaobj0 .setAttribute ("rows","2");
  tdobj0 .appendChild(textareaobj0 );
  trobj .appendChild (tdobj0 );
   
  // 添加td1
  var tdobj1 = document .createElement ("td");
  tdobj1 .setAttribute ("class","td1");
  var textobj1 = document .createElement ("input");
  textobj1.setAttribute ("id","tb_line"+linenu