js:table选择指定行,并获取指定数据

第一种:

jsp:

	
								 项次
                                名称                             
                             
                            
                            
                               	"
										PD2=""

										onclick="javascript:GetRow(this);"
										onmouseover="javascript:if (this.className!='TableRowSelected') this.className='TableRowOver'"
										onmouseout="javascript:if (this.className!='TableRowSelected') this.className='TableRow'">
										
                                        ${s.count}
                                    
                           ......
 
 

js:

function GetRow(node)
{
    RowSelect(node);
}

function RowSelect(row,name)
{ 
    if (!name) name="row";
	if (window[name])
	{
   //这是添加样式
	//	window[name].className = window[name].getAttribute("oldClass");
	}
//这是添加样式
//	row.className = "TableRowSelected";
	window[name] = row;	
}
// 以上可抽出,做公用方法
-----------------------------
   //获取指定的值
	this.edit = function edit(row) {
   var pd1=row.getAttribute("PD1");
	}

jsp中方法:onclick="javascript:xxx.edit(window.row)"

第二种方法:

  

function GetRow(node)
{
     var row = $(node);//获取当前行
     var ss= $(node).children();  
    var code = $(row).find("td:eq(0)").text();//获取当前行的第一列单元格内容
    var name = $(row).find("td:eq(1)").text();//
   
//遍历获取指定行所有字段值
   for (var int = 0; int < ss.length; int++) {
		alert($(row).find("td:eq('"+int+"')").text());
	}
//获取指定行指定字段值
    alert(row.attr("PD1"));
}

 

你可能感兴趣的:(js)