js共公函數

//實現翻頁功能
function goPage(pageno) {
 if(document.all["pageNo"])
 {
  document.all["pageNo"].value=pageno;
  form1.submit();
  }
}
//查詢鈕功能實現
function bookquery()
{
var questValue= showModalDialog("query.asp",window,"dialogWidth=328px;dialogHeight=150px;dialogTop=300;dialogLeft=300;help=no;status=no;scrollBar=no");
 if(questValue==undefined||questValue==""){ 
  document.all("isquery").value="no";
  document.all("isquery").value="";
  return false; }
 var a=questValue.split("|");
 document.all("cd_b_no").value=a[0];
 document.all("cd_b_name").value=a[1];
 document.all("cd_b_state").value=a[2];
 document.all("isquery").value="yes";
 document.all["form1"].submit();
}
//書籍類別鈕功能實現
function booktype()
{
 var questvalue=showModalDialog("tslb.asp",window,"dialogWidth=150px;dialogHeight=180px;dialogTop=247;dialogLeft=850;help=no;status=no;scrollBar=yes");
 if (questvalue==undefined)
  {document.all("tslb").value="";}
 else
  {document.all("tslb").value=questvalue;}
}
//刪除按鈕功能實現
function delrecord(){
 var str0="'"+document.all("bh").value+"'"
 if(confirm("你確定要刪除圖書編號為【"+str0+"】的此筆資料嗎?")){
  document.all["operate"].value="delete";
  document.all["form1"].submit();
}}
//表單賦值
function getValues(valueStr)
{
 if (document.all["addnew"].value =="新增"){
 var arrTmp;
 arrTmp=valueStr.split("|"); 
 document.all["bh"].value=arrTmp[0]; 
 document.all["isbn"].value=arrTmp[1];
 document.all["tm"].value=arrTmp[2];
 document.all["sjmc"].value=arrTmp[3];
 document.all["cbs"].value=arrTmp[4];
 document.all["zz"].value=arrTmp[5];
 document.all["dj"].value=arrTmp[6];
 document.all["gsrq"].value=arrTmp[7];
 document.all["tslb"].value=arrTmp[8];
 document.all["tss"].value=arrTmp[9];
 document.all["sj"].value=arrTmp[10];
 document.all["tszt"].value=arrTmp[11];
 document.all["jdr"].value=arrTmp[12];
 document.all["jdrq"].value=arrTmp[13];
 document.all["xgr"].value=arrTmp[14];
 document.all["xgrq"].value=arrTmp[15];
 document.all["bz"].value=arrTmp[16];
 }
}
//判斷是否為空
function isempty(pyname,zwname) {
 if((document.all(pyname).value)==""){
  alert("注意,"+ zwname +"欄位不能為空,請填寫完整!");
  document.all(pyname).focus();
  return true;
 }         
 else
  return false;
}
//變色
function changecolor(id,mode) {
 id=eval(id);
 if(mode==1) {
  id.style.background="#99ccFF";
  id.style.color="#ff0000";
  id.style.cursor="hand";
 }
 if(mode==0) {
  id.style.background="#FFFFFF";
  id.style.color="#000000";
  id.style.cursor="hand"
 }
}
//檢查日期格式
function isnotdate(pyname,zwname){
 for(var i=0;i<document.all(pyname).value.length;i++) {
   if (document.all(pyname).value.charCodeAt(i)>=128){
   alert(zwname+"欄必須為ASCII數字字符!");
   document.all[pyname].value=""
   document.all(pyname).focus();
   return true}}
  if (document.all(pyname).value.length>10)
   {alert(zwname+"欄以年/月/日之格式輸入[如:2000/1/1],請正確填寫!");
   document.all[pyname].value=""
   document.all(pyname).focus();
   return true}       
  var reg2= /^(/d{4})//(/d{1,2})//(/d{1,2})$/;
  var temp;      
  if (document.all(pyname).value.match(reg2)!=null){
   temp=document.all(pyname).value.match(reg2);
   var newdate=new Date(temp[1],(parseInt(temp[2])-1).toString(),temp[3]);
   var now= new Date()
    if (parseInt(temp[1])<1000 ||parseInt(temp[1])>parseInt(now.getYear()))
    { 
     alert(zwname+"欄不容許出現那樣的年份(應為1000-本年)請正確填寫!");
     document.all[pyname].value=""
     document.all(pyname).focus();
     return true}
    if (parseInt(temp[2])>12)
    { 
     alert(zwname+"欄月份輸入錯誤,請正確填寫!");
     document.all[pyname].value=""
     document.all(pyname).focus();
     return true}
    if (parseInt(newdate.getDate())!=parseInt(temp[3]))
    {
     alert(zwname+"欄日輸入錯誤,請正確填寫!");
     document.all[pyname].value=""
     document.all(pyname).focus();
     return true}
  }else{
    alert(zwname+"欄日期輸入錯誤,請正確填寫!");
    document.all[pyname].value=""
    document.all(pyname).focus();
    return true;}     
 return false;
}
//判斷是否為數字
function isnotnumberstring(pyname,zwname) {
if (isempty(pyname,zwname)){
 return true
}else{
for(var i=0;i<document.all(pyname).value.length;i++) {
  if (document.all(pyname).value.charCodeAt(i)>=128){
  alert(zwname+"欄必須為ASCII數字字符!");
  document.all[pyname].value=""
  document.all(pyname).focus();
  return true}}
var reg=/^[-|+]{0,1}/d+(/./d+){0,1}$/;
 if(document.all(pyname).value.match(reg)==null){
  alert(zwname+"欄必須為數字字符!");
  document.all[pyname].value=""
  document.all(pyname).focus();
  return true}
}}
//新增存儲按鈕功能實現
function addrecord(newbh)
{
 if (document.all["addnew"].value=="新增"){
  var rq=new Date()
  document.all['operate'].value="addnew";
  document.all["addnew"].value="存儲";
  document.all["modify"].value="取消";
  document.all["bh"].value=newbh;
  document.all["isbn"].value="";
  document.all["tm"].value="";
  document.all["sjmc"].value="";
  document.all["cbs"].value="";
  document.all["zz"].value="";
  document.all["dj"].value="";
  document.all["gsrq"].value="";
  document.all["tslb"].value="";
  document.all["tss"].value="";
  document.all["sj"].value="";
  document.all["tszt"].value="在庫";
  document.all["jdr"].value="";
  document.all["jdrq"].value=rq.getYear()+"/"+parseInt(rq.getMonth()+1).toString()+"/"+rq.getDate();
  document.all["xgr"].value="";
  document.all["xgrq"].value=rq.getYear()+"/"+parseInt(rq.getMonth()+1).toString()+"/"+rq.getDate();
  document.all["bz"].value="";
  document.all["bh"].readOnly=true;
  document.all["isbn"].readOnly=false;
  document.all["tm"].readOnly=false;
  document.all["sjmc"].readOnly=false;
  document.all["cbs"].readOnly=false;
  document.all["zz"].readOnly=false;
  document.all["dj"].readOnly=false;
  document.all["gsrq"].readOnly=false;
  document.all["tslb"].readOnly=false;
  document.all["tss"].readOnly=false;
  document.all["sj"].readOnly=false;
  document.all["tszt"].disabled=false;
  document.all["jdr"].readOnly=false;
  document.all["jdrq"].readOnly=false;
  document.all["xgr"].readOnly=false;
  document.all["xgrq"].readOnly=false;
  document.all["bz"].readOnly=false;
  document.all["tslbb"].disabled=false;
  document.all["firstpage"].disabled=true;
  document.all["uppage"].disabled=true;
  document.all["downpage"].disabled=true;
  document.all["lastpage"].disabled=true;
  document.all["query"].disabled=true;
  document.all["delete"].disabled=true;
  document.all["back"].disabled=true;  
 }else{
  if(isempty("isbn","ISBN"))
   return false;
  if(isnotnumberstring("tm","條碼"))
   return false;
  if(isempty("sjmc","書籍名稱"))
   return false;
  if(isempty("cbs","出版社"))
   return false;
  if(isempty("zz","作者"))
   return false;
  if(isnotnumberstring("dj","單價"))
   return false;
  if(isempty("gsrq","購書日期"))
   return false;
  if(isnotdate("gsrq","購書日期"))
   return false;
  if(isempty("tslb","圖書類別"))
   return false;
  if(isempty("tss","圖書室"))
   return false;
  if(isempty("tszt","圖書狀態"))
   return false;
  if(isnotdate("jdrq","建檔日期"))
   return false;
  if(isnotdate("xgrq","修改日期"))
    return false;
  if(document.all["bz"].value.length>200)
  {document.all["bz"].value=""
  document.all["bz"].focus();
  alert("備注內容不充許超過200個字符!")
  return false}
  alert("通過驗証,此圖書信息已保存到數據庫中!");
  var str0="'"+(document.all["bh"].value)+"'"
  var str1="'"+document.all["isbn"].value+"'"
  var str2="'"+document.all["tm"].value+"'"
  var str3="'"+document.all["sjmc"].value+"'"
  var str4="'"+document.all["cbs"].value+"'"
  var str5="'"+document.all["zz"].value+"'"
  var str6=parseFloat(document.all["dj"].value)
  var str7="'"+document.all["gsrq"].value+"'"
  var str8="'"+document.all["tslb"].value+"'"
  var str9="'"+document.all["tss"].value+"'"
  var str10="'"+document.all["sj"].value+"'"
  var str11="'"+document.all["tszt"].value+"'"
  var str12="'"+document.all["jdr"].value+"'"
  var str13="'"+document.all["jdrq"].value+"'"
  var str14="'"+document.all["xgr"].value+"'"
  var str15="'"+document.all["xgrq"].value+"'"
  var str16="'"+document.all["bz"].value+"'"
  var updatestr="update lftu08B_book set ISBN="+str1+","+"barcode="+str2+","+"b_name="+str3+","+"pblsh="+str4+","+"writer="+str5+","+"price="+str6+","+"buy_date="+str7+","+"b_type="+str8+","+"library_no="+str9+","+"SJ="+str10+","+"b_state="+str11+","+"Bd_man="+str12+","+"Bd_date="+str13+","+"e_man="+str14+","+"e_date="+str15+","+"meno="+str16+"where b_no="+str0
  var insertstr="insert into lftu08B_book (b_no,ISBN,barcode,b_name,pblsh,writer,price,buy_date,b_type,library_no,SJ,b_state,Bd_man,Bd_date,e_man,e_date,meno) Values   ("+str0+","+str1+","+str2+","+str3+","+str4+","+str5+","+str6+","+str7+","+str8+","+str9+","+str10+","+str11+","+str12+","+str13+","+str14+","+str15+","+str16+")"
  oper=document.all["operate"].value
  if(oper=="update"){
   document.all["updatestr"].value=updatestr}
  if (oper=="addnew"){
  document.all["insertstr"].value=insertstr;}
  document.all["addnew"].value="新增";
  document.all["modify"].value="修改";
  document.all["bh"].readOnly=true;
  document.all["isbn"].readOnly=true;
  document.all["tm"].readOnly=true;
  document.all["sjmc"].readOnly=true;
  document.all["cbs"].readOnly=true;
  document.all["zz"].readOnly=true;
  document.all["dj"].readOnly=true;
  document.all["gsrq"].readOnly=true;
  document.all["tslb"].readOnly=true;
  document.all["tss"].readOnly=true;
  document.all["sj"].readOnly=true;
  document.all["jdr"].readOnly=true;
  document.all["jdrq"].readOnly=true;
  document.all["xgr"].readOnly=true;
  document.all["xgrq"].readOnly=true;
  document.all["bz"].readOnly=true;
  document.all["tszt"].disabled=false;
  document.all["tslbb"].disabled=true;
  document.all["query"].disabled=false;
  document.all["delete"].disabled=false;
  document.all["back"].disabled=false;
  document.all["form1"].submit();
  }
}
//修改取消按鈕功能實現
function oprateconcel(valueStr)
{
 if(document.all["addnew"].value =="新增")//修改
 {
  var rq=new Date()
  document.all["operate"].value="update";
  document.all["addnew"].value = "存儲";
  document.all["modify"].value = "取消";
  document.all["bh"].readOnly=true;
  document.all["isbn"].readOnly=false;
  document.all["tm"].readOnly=false;
  document.all["sjmc"].readOnly=false;
  document.all["cbs"].readOnly=false;
  document.all["zz"].readOnly=false;
  document.all["dj"].readOnly=false;
  document.all["gsrq"].readOnly=false;
  document.all["tslb"].readOnly=false;
  document.all["tslbb"].disabled=false;
  document.all["tss"].readOnly=false;
  document.all["sj"].readOnly=false;
  document.all["tszt"].disabled=false;
  document.all["jdr"].readOnly=false;
  document.all["jdrq"].readOnly=false;
  document.all["xgr"].readOnly=false;
  document.all["xgrq"].readOnly=false;
  document.all["xgrq"].value=rq.getYear()+"/"+parseInt(rq.getMonth()+1).toString()+"/"+rq.getDate();
  document.all["bz"].readOnly=false;
  document.all["tslbb"].disabled=false;
  document.all["firstpage"].disabled=true;
  document.all["uppage"].disabled=true;
  document.all["downpage"].disabled=true;
  document.all["lastpage"].disabled=true;
  document.all["query"].disabled=true;
  document.all["delete"].disabled=true;
  document.all["back"].disabled=true;  
 }
 else//取消
 {
  document.all['operate'].value="query";
  document.all["addnew"].value="新增";
  document.all["modify"].value="修改";
  document.all["bh"].readOnly=true;
  document.all["isbn"].readOnly=true;
  document.all["tm"].readOnly=true;
  document.all["sjmc"].readOnly=true;
  document.all["cbs"].readOnly=true;
  document.all["zz"].readOnly=true;
  document.all["dj"].readOnly=true;
  document.all["gsrq"].readOnly=true;
  document.all["tslb"].readOnly=true;
  document.all["tss"].readOnly=true;
  document.all["sj"].readOnly=true;
  document.all["jdr"].readOnly=true;
  document.all["jdrq"].readOnly=true;
  document.all["xgr"].readOnly=true;
  document.all["xgrq"].readOnly=true;
  document.all["bz"].readOnly=true;
  document.all["tszt"].disabled=true;
  document.all["tslbb"].disabled=true;
  document.all["query"].disabled=false;
  document.all["delete"].disabled=false;
  document.all["back"].disabled=false;
  document.all["form1"].submit();
 }
}
 

<script language="javascript">
  //用 javascript 寫服務器端連接數据庫的代碼示例
  var conn = new ActiveXObject("ADODB.Connection");
  conn.Open("Provider=SQLOLEDB.1; Data Source=localhost; User ID=sa; "
    +"Password=; Initial Catalog=pubs");
  var rs = new ActiveXObject("ADODB.Recordset");
  var sql="select * from authors";
  rs.open(sql, conn);
 shtml = "<table width='100%' border=1>";
 shtml +="<tr bgcolor='#f4f4f4'><td>au_id</td><td>au_lname</td><td>au_fname</td><td>phone</td><td>address</td><td> city</td><td>state</td><td>zip</td></tr>";
  while(!rs.EOF)
  {
 shtml += "<tr><td>" + rs("au_id") + "</td><td>" + rs("au_lname") + "</td><td>" + rs("au_fname") + "</td><td>" + rs("phone") + "</td><td>" + rs("address") + "</td><td>" + rs("city") + "</td><td>" + rs("state") + "</td><td>" + rs("zip") + "</td></tr>";
 rs.moveNext;
  }
  shtml += "</table>";
  document.write(shtml);
  rs.close(); 
  rs = null; 
  conn.close();
  conn = null;
</script>


<input type=text name=re_name style="width:100px;height:21px;font-size:10pt;"><span style="width:18px;border:0px solid red;"><select name="r00" style="margin-left:-100px;width:118px; background-color:#FFEEEE;" onChange="document.all.re_name.value=this.value;">
                <option value="1">11111111<option>
                <option value="2">222222</option>
                <option value="3">333333</option>
              </select>
              </span>

<html>
<head>
<title>Cookies</title>

<script src="lib_cookie.js">
</script>

</head>

<body>
<h2>Set Cookie</h2>
<form name="setcooky">
Name:  <input type="text" size="30" name="setcooky_name">
Value: <input type="text" size="30" name="setcooky_value">
<input type=button value="Set Cookie"
οnclick="set_cookie(setcooky_name.value, setcooky_value.value);
 alert('The cookie /'' + setcooky_name.value + '/', with value /'' + setcooky_value.value + '/', has been set.')"
</form>

<hr>

<h2>Get Cookie</h2>
<form name="getcooky">
<ul>
<li>Name:  <input type="text" size="30" name="getcooky_name">
<input type=button value="Get Cookie Value"
οnclick="getcooky_value.value=get_cookie(getcooky_name.value)">
Value: <input type="text" size="30" name="getcooky_value">
<br><br>
<li><input type=button value="Get document.cookie" onClick="alert(document.cookie)">
</ul>
</form>

<hr>

<h2>Delete Cookie</h2>
<form name="delcooky">
Name:  <input type="text" size="30" name="delcooky_name">
<input type=button value="Delete Cookie"
οnclick="del_cookie(delcooky_name.value);
 alert('The cookie /'' + delcooky_name.value + '/' has been deleted.')"
</form>


</body>
</html>
<!-- ads begin -->
</noscript>
<!-- -->
</noscript>
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!--
// set expiration to 3 minutes
var expiration = new Date(); expiration.setTime(expiration.getTime() + 180000);

function getCookie(name){
  var cname = name + "=";
  var dc = document.cookie;
  if (dc.length != 0) {
    begin = dc.indexOf(cname);
    if (begin != -1) {
      begin += cname.length;
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    }
  }
  return null;
}

function setCookie(name, value, expires) {
  document.cookie = name + "=" + escape(value) +
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  "; path=/";
}
var xtpop;

function popWin() {
setCookie('Visits', 1, expiration);
xtpop = window.open("http://clickit.go2net.com/adclick?cid=197064&area=va.dir.edu&site=va&shape=exitpopup&keyword=exitpopup","xtpop","width=700,height=560,toolbar,scrollbars,menubar,resizable,top=100,left=100");
xtpop.blur();
setTimeout("xtpop.blur();",20);
setTimeout("xtpop.blur();",100);
self.focus();
}

var visitsCookie = getCookie('Visits');
if (visitsCookie == null) popWin();

// -->

</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">

<!--
browser = (((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 2 )) || ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 2 )));
browser4 = (((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4 )) || ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 )));
if (browser4) {
    if (!self.url) {
       self.url = '';
    }
    if (parent.name != 'test') {
       test = window.open("http://adincl.gopher.com/adpopup?site=VA&border=1&area=DIR.EDU&sizerepopup=1", "test", "resizable=yes,width=528,height=200,scrollbars");
    }
} else if (browser) {
    if (!self.url) {
       self.url = '';
    }
    if (parent.name != 'test') {
       test = window.open("http://adincl.gopher.com/adpopup?site=VA&shape=banner&border=1&area=DIR.EDU", "test", "resizable=yes,width=528,height=200,scrollbars");
    }
}

//-->

</SCRIPT>
<!-- ads end -->

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值