插入光标所在的Text
<input onblur="global=this"><br/>
<input onblur="global=this"><br/>
<input type=button value=meizz onclick="mm()">
<SCRIPT LANGUAGE="javascript">
var global = null; //记录是要在哪个文本框里插入
function mm()
{
var old = window.clipboardData.getData("Text");
var txt = window.prompt("请输入", "");
if(txt && global)
{
window.clipboardData.setData("Text", txt);
global.focus();
document.execCommand('Paste');
global=null;
}
window.clipboardData.setData("Text", old);
}
</SCRIPT>
按回车提交
<script language="javascript">
<!--
document.onkeydown=function()
{
loginform.submit()
}
//-->
</script>
改变td的状态
<script>
function Click_B(){
div1.innerHTML = "<input type=text id=t1>";
//div1.innerTEXT = "test";
}
function Click_B2(){
div1.innerHTML = t1.value;
}
</script>
<table><tr><td><div id=div1>点击以前</div></td></tr></table>
<input type=button value="更改" onclick="Click_B()">
<input type=button value="保存" onclick="Click_B2()">
判断复选框是否选中
<script language="javascript">
<!--
function check()
{
var o1 = document.getElementsByName('r');
var o2 = document.getElementsByName('c');
var i;
var j=0,p=0;
for(i=0;i<o1.length;i++)
{
if(o1[i].checked)
{
alert('选中的单选按钮ID:'+o1[i].id);
j++;
}
}
if(j==0) alert('没选择单选按钮!');
for(i=0;i<o2.length;i++)
{
if(o2[i].checked)
{
alert('选中的多选按钮ID:'+o2[i].id);
p++;
}
}
if(p==0) alert('没选择多选按钮!');
}
//-->
</script>
<input type=radio name=r id=r1>r1
<input type=radio name=r id=r2>r2
<input type=radio name=r id=r3>r3
<br>
<input type=checkbox name=c id=c1>c1
<input type=checkbox name=c id=c2>c2
<input type=checkbox name=c id=c3>c3
<input type=checkbox name=c id=c4>c4
<input type=checkbox name=c id=c5>c5
<p><input type=button value=check onclick="check();"></p>
取Input的值
<script language="javascript">
<!--
function check()
{
var o = document.getElementsByTagName('INPUT');
for(var i=0;i<o.length;i++)
{
if(o[i].type == 'radio' && o[i].checked) alert('选中单选框的value:'+o[i].value);
if(o[i].type == 'checkbox' && o[i].checked) alert('选中复选框的value:'+o[i].value);
}
}
//-->
</script>
全选
<form name=meizz>
<input type=checkbox name=All onclick="checkAll('mm')">??<br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/><br/>
<input type=checkbox name=All2 onclick="checkAll('mm2')">??<br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
</form>
<SCRIPT LANGUAGE="JavaScript">
function checkAll(str)
{
var a = document.getElementsByName(str);
var n = a.length;
for (var i=0; i<n; i++)
a[i].checked = window.event.srcElement.checked;
}
function checkItem(str)
{
var e = window.event.srcElement;
var all = eval("document.meizz."+ str);
if (e.checked)
{
var a = document.getElementsByName(e.name);
all.checked = true;
for (var i=0; i<a.length; i++)
{
if (!a[i].checked){ all.checked = false; break;}
}
}
else all.checked = false;
}
</SCRIPT>
<input type=radio name=r value=1>
<input type=radio name=r value=2>
<input type=radio name=r value=3>
<p>
<input type=checkbox name=c value=1>
<input type=checkbox name=c value=2>
<input type=checkbox name=c value=3>
<p>
<input type=button value=check onclick="check();">
如何获得Td的行数
<table border=1>
<tr>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
</tr>
<tr>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
</tr>
<tr>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
</tr>
</table>
---------------------------------------
根据td,可以如下:
oTd.parentNode.parentNode.parentNode.rows.length 行数
oTd.parentNode.cells.length 列数
------------------------------------------
oTd.parentNode.parentNode.rows.length 行数
如何进行全文替换
<script>
var strText = new String() ;
strText="<input type=text><input type=submit>"
alert( strText ) ;
var re = new RegEXP ("<", "gi") ;
var newstr = strText.replace(re, "<") ;
alert( newstr ) ;
</script>
时间格式
<script language=javascript>
alert("2004-9-3".replace(/\-(\d{1})/ig,"-0$1"))
</script>
<script language="vbScript" >
set re = new RegExp
re.Pattern = "\-(\d{1})"
re.Global = true
msgbox re.Replace("2004-9-3", "-0$1")
set re =nothing
</script>
中文标点的判断
<input type=text name=a>
<input type=button value="提交" onclick="chk()">
<script language="JavaScript">
function chk()
{
b=/^\s*[A-Za-z0-9\u4e00-\u9fa5,。;:“”‘’!?、]*\s*$/;
c=document.all.a.value;
if (c.replace(b,"")!="")
{
alert("您输入了非法字符");
}
}
</script>
<input onblur="global=this"><br/>
<input onblur="global=this"><br/>
<input type=button value=meizz onclick="mm()">
<SCRIPT LANGUAGE="javascript">
var global = null; //记录是要在哪个文本框里插入
function mm()
{
var old = window.clipboardData.getData("Text");
var txt = window.prompt("请输入", "");
if(txt && global)
{
window.clipboardData.setData("Text", txt);
global.focus();
document.execCommand('Paste');
global=null;
}
window.clipboardData.setData("Text", old);
}
</SCRIPT>
按回车提交
<script language="javascript">
<!--
document.onkeydown=function()
{
loginform.submit()
}
//-->
</script>
改变td的状态
<script>
function Click_B(){
div1.innerHTML = "<input type=text id=t1>";
//div1.innerTEXT = "test";
}
function Click_B2(){
div1.innerHTML = t1.value;
}
</script>
<table><tr><td><div id=div1>点击以前</div></td></tr></table>
<input type=button value="更改" onclick="Click_B()">
<input type=button value="保存" onclick="Click_B2()">
判断复选框是否选中
<script language="javascript">
<!--
function check()
{
var o1 = document.getElementsByName('r');
var o2 = document.getElementsByName('c');
var i;
var j=0,p=0;
for(i=0;i<o1.length;i++)
{
if(o1[i].checked)
{
alert('选中的单选按钮ID:'+o1[i].id);
j++;
}
}
if(j==0) alert('没选择单选按钮!');
for(i=0;i<o2.length;i++)
{
if(o2[i].checked)
{
alert('选中的多选按钮ID:'+o2[i].id);
p++;
}
}
if(p==0) alert('没选择多选按钮!');
}
//-->
</script>
<input type=radio name=r id=r1>r1
<input type=radio name=r id=r2>r2
<input type=radio name=r id=r3>r3
<br>
<input type=checkbox name=c id=c1>c1
<input type=checkbox name=c id=c2>c2
<input type=checkbox name=c id=c3>c3
<input type=checkbox name=c id=c4>c4
<input type=checkbox name=c id=c5>c5
<p><input type=button value=check onclick="check();"></p>
取Input的值
<script language="javascript">
<!--
function check()
{
var o = document.getElementsByTagName('INPUT');
for(var i=0;i<o.length;i++)
{
if(o[i].type == 'radio' && o[i].checked) alert('选中单选框的value:'+o[i].value);
if(o[i].type == 'checkbox' && o[i].checked) alert('选中复选框的value:'+o[i].value);
}
}
//-->
</script>
全选
<form name=meizz>
<input type=checkbox name=All onclick="checkAll('mm')">??<br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/><br/>
<input type=checkbox name=All2 onclick="checkAll('mm2')">??<br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
</form>
<SCRIPT LANGUAGE="JavaScript">
function checkAll(str)
{
var a = document.getElementsByName(str);
var n = a.length;
for (var i=0; i<n; i++)
a[i].checked = window.event.srcElement.checked;
}
function checkItem(str)
{
var e = window.event.srcElement;
var all = eval("document.meizz."+ str);
if (e.checked)
{
var a = document.getElementsByName(e.name);
all.checked = true;
for (var i=0; i<a.length; i++)
{
if (!a[i].checked){ all.checked = false; break;}
}
}
else all.checked = false;
}
</SCRIPT>
<input type=radio name=r value=1>
<input type=radio name=r value=2>
<input type=radio name=r value=3>
<p>
<input type=checkbox name=c value=1>
<input type=checkbox name=c value=2>
<input type=checkbox name=c value=3>
<p>
<input type=button value=check onclick="check();">
如何获得Td的行数
<table border=1>
<tr>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
</tr>
<tr>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
</tr>
<tr>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentElement.rowIndex+1)+"\n列数:"+(this.cellIndex+1))'>点我</td>
</tr>
</table>
---------------------------------------
根据td,可以如下:
oTd.parentNode.parentNode.parentNode.rows.length 行数
oTd.parentNode.cells.length 列数
------------------------------------------
oTd.parentNode.parentNode.rows.length 行数
如何进行全文替换
<script>
var strText = new String() ;
strText="<input type=text><input type=submit>"
alert( strText ) ;
var re = new RegEXP ("<", "gi") ;
var newstr = strText.replace(re, "<") ;
alert( newstr ) ;
</script>
时间格式
<script language=javascript>
alert("2004-9-3".replace(/\-(\d{1})/ig,"-0$1"))
</script>
<script language="vbScript" >
set re = new RegExp
re.Pattern = "\-(\d{1})"
re.Global = true
msgbox re.Replace("2004-9-3", "-0$1")
set re =nothing
</script>
中文标点的判断
<input type=text name=a>
<input type=button value="提交" onclick="chk()">
<script language="JavaScript">
function chk()
{
b=/^\s*[A-Za-z0-9\u4e00-\u9fa5,。;:“”‘’!?、]*\s*$/;
c=document.all.a.value;
if (c.replace(b,"")!="")
{
alert("您输入了非法字符");
}
}
</script>