动态添加表格一行(javascript)
<%@ page language="java" import="java.util.*,com.page.wash.giveclothing.*" pageEncoding="gbk"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>添加表格信息</title>
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
<meta http-equiv="description" content="This is my page" />
<mce:script language="javascript" type="text/javascript"><!--
function AddRow()
{
//添加一行
var i =tab1.rows.length;
var Nam="'div1'";
var Cod="fuJ"+i;
var newTr = tab1.insertRow();
//添加列
var newTd0 = newTr.insertCell();
var newTd1 = newTr.insertCell();
var newTd2 = newTr.insertCell();
var newTd3 = newTr.insertCell();
//设置列内容和属性
newTd0.innerHTML = '<input type="checkbox" id="box1" onClick="GetRow()"/ /><input type="hidden" name="fuJ" id='+Cod+' />';
newTd1.innerHTML = " 衣服尺码";
newTd2.innerHTML = " 衣服花色";
newTd3.innerHTML = " 处理类型";
}
function DelRow()
{
//删除一行
var shu=0;
var cheCou=document.all("box1");
for(var i=0;i<cheCou.length;i++)
{
if (cheCou[i].checked==true)
{
shu++;
}
}
if(shu==cheCou.length)
{
alert('最少要添加一件衣服');
return;
}
else if(shu==0)
{
alert('请选择你要删除的信息');
return;
}
else if(shu==1)
{
for(var i=0;i<cheCou.length;i++)
{
if(cheCou[i].checked==true)
{
tab1.deleteRow(i+1);
}
}
}
else if(shu>1)
{
for(var a=0;a<shu;a++)
{
for(var i=0;i<cheCou.length;i++)
{
if(cheCou[i].checked==true)
{
tab1.deleteRow(i+1);
break;
}
}
}
}
}
相关文档:
FireFox : addEventListener()方法 IE : attachEvent()方法 为HTML元素添加一个事件监听, 而不是直接对元素的事件属性(如:onclick、onmouseover)赋值。 这两种方法处理事件还是有很大区别的!事件属性只能赋值一种方法,即: button1.onclick = function() { alert(1); };
button1.onclick = function() { aler ......
如果使用html控件还好一些,服务器控件就比较郁闷一些,因为GridView生成之后是多行的,所以这个文本框也会有很多个,另一方面asp.net会自动重新命名控件,所以想通过ID获取已经不可能了,很不幸的是连name属性都被自动生成了,哪怕你添加了name属性,也无法覆盖生成的name,而是会出来两个name属性
那么就想别的办法, ......
事件源对象
event.srcElement.tagName
event.srcElement.type
捕获释放
event.srcElement.setCapture();
event.srcElement.releaseCapture();
事件按键
event.keyCode
event.shiftKey
event.altKey
event.ctrlKey
事件返回值
event.returnValue
鼠标位置
eve ......
JavaScript的方法和技巧 收藏
有些时候你精通一门语言,但是会发现你其实整天在和其它语言打交道,也许你以为这些微不足道,不至于影响你的开发进度,但恰恰是这些你不重视的东西会浪费 你很多时间,我一直以为我早在几年前就已经精通JavaScript了,直到目前,我才越来越觉得JavaScript远比我想象的复杂和强大,我开始崇 ......