<!DOCTYPE HTML>
var sexArr=new Array("female","male");
var removeArr=new Array();
var addArr=new Array();
var addCount=0;
function removeRows()
{
var ckArr=$("input[name='rows']");
for(var i=0;i<ckArr.length;i++)
{
var currentCheckBox=ckArr[i];
var val=currentCheckBox.checked;
if(val==true)
{
var currenRow=$(currentCheckBox).parent().parent();
var
currenRow.remove();
alert("删除。。。。。。。。。");
}
}
}
function txtInputBlur(inputTxt)
{
var txtInputCount=$(inputTxt).val();
var parent=$(inputTxt).parent();
$(inputTxt).remove();
parent.text(txtInputCount);
parent.bind("click",function(){
tdClick(this);
});
}
function tdClick(td)
{
debugger;
var txt =$(td).text();
var txtInput="<input type='text' value='"+txt+"' onblur='txtInputBlur(this)' />";
$(td).html(txtInput);
$(td).unbind("click");
$(td).removeAttr("onclick");
$(td).children("input").focus();
}
function addRow()
{
var charcode=Math.floor(Math.random()*26)+97;
var tempName=String.fromCharCode(charcode,charcode,charcode);
var tempAge=18+Math.round(7*Math.random());
var sexIndx=Math.round(Math.random());
var newRow="<tr><td><input type=\"checkbox\" name=\"rows\" /></td><td onclick='tdClick(this)'>"+tempName+"</td><td onclick='tdClick(this)'>"+tempAge+"</td><td onclick='tdClick(this)'>"+sexArr[sexIndx]+"</td></tr>";
$("#mytable").append(newRow);
addArr[addCount]=new Array(tempName,tempAge,sexArr[sexIndx]);
addCount++;
for(var i=0;i<addArr.length;i++)
{
alert("姓名:"+addArr[i][0]+" 年龄:"+addArr[i][1]+" 性别:"+addArr[i][2]+"<br>");
}
}
$(document).ready(function(){
$(".tdcontent").bind("click",function(){
tdClick(this);
});
});
Operte |
Name |
Age |
Sex |
|
aaa |
18 |
female |