javascript 用点滴

来源:互联网 发布:淘宝无序列号的kindle 编辑:程序博客网 时间:2024/04/28 20:36

1,判断一个对象是否定义(存在): if(historyArray == undefined)

2,关于在html页面之中动态的创建一个table,并且在table之中动态添加行列:

//创建一个table对象

var vTable=document.createElement("table");

//设置table的属性

vTable.setAttribute("cellPadding","1");
vTable.setAttribute("cellSpacing","1");
vTable.setAttribute("border","0");

//插入一行

vTr=vTable.insertRow(kIndex);

//插入一列

vTd=vTr.insertCell(iIndex);

//设置列属性

vTd.style.background="#7596C6";
vTd.align="center";

vTd.style.background="#0066CC";

//插入这一列中显示的html

vTd.innerHTML="<input type='text' name='bt_row_col' class='creattable_inputfield'>";

DivID.appendChild(vTable);

========================

在普通html语句之中需要有:

<table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" class="">
  <tr>
    <td width="5"><div id="DivID"></div></td>
  </tr>
</table>

===============================================

以上就是在html页面之中动态插入table的方法了。

3,关于如何在提交表单之前校验数据.
form之中:
<form name="form1" method="post" action="" onsubmit="return check(form1);">
然后写一个javascript:
function check(form)
{
    if(...)
    {
        return false;
    }
    return true;
}
如果check()方法之中返回true,则提交,反之,则不会submit了!

 

原创粉丝点击