有个问题请教(LxcJie看到一定要进,因为是看了你的帖子的疑问)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME= "Generator " CONTENT= "EditPlus ">
<META NAME= "Author " CONTENT= " ">
<META NAME= "Keywords " CONTENT= " ">
<META NAME= "Description " CONTENT= " ">
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
</HEAD>
<BODY>
<form name= "form1 " method= "post " action= " ">
日期: <input type= "text " id= "a " onclick= "restrictInputValue(this) " onkeydown= "ddd(this) " >
</form>
</BODY>
</HTML>
<script language= "javascript ">
window.onload=init;
function init(){
var oDate = new Date();
var result= oDate.getFullYear()+ "- "+(oDate.getMonth() <10?( "0 " + (oDate.getMonth()+1)):(oDate.getMonth()+1))+ "- "+(oDate.getDate() <10?( "0 " + oDate.getDate()) : oDate.getDate());
document.getElementById( "a ").value=result;
}
function restrictInputValue(obj)
{
var range = obj.createTextRange();
var selRange = document.selection.createRange();
range.moveStart( "character ",-obj.value.length)
selRange.setEndPoint( "StartToStart ",range);
if(selRange.text.length <5){
specialText_SelectYear(obj);
}
else if(selRange.text.length> 4&&selRange.text.length <8){
specialText_SelectMonth(obj)
}
else{
specialText_SelectDate(obj)
}
}
function specialText_SelectYear(oInput)
{
var oRange = oInput.createTextRange();
oRange.moveStart( "character ",0);
oRange.moveEnd( "character ",-6);
//代表选中了年
oInput.selectIndex = 1;
oRange.select();
}
//选中月份
function specialText_SelectMonth(oInput)
{
var oRange = oInput.createTextRange();
oRange.moveStart( "character ",5);
oRange.moveEnd( "character ",-3);