常用JS函数

来源:互联网 发布:linux usleep range 编辑:程序博客网 时间:2024/05/16 00:38

 //去前后空格
   String.prototype.trim = function()
   {
     return this.replace(/(^/s+)|/s+$/g,"");
   }

 

  //弹出对话框(自动关闭)
 function autoCloseAlert(msg)
 {
  try
    {
    var tempFrm=document.getElementById("msgFrm");
    if(tempFrm==null||typeof(tempFrm)=="undefined")
    {
   tempFrm =document.createElement("iframe");
   document.body.appendChild(tempFrm);
   tempFrm.id = "msgFrm";
   tempFrm.name ="msgFrm";
   tempFrm.style.display="none";
    }
    msg=msg.replace(/"/g,"///"");
    msg=msg.replace(//n/g,"//n");
    var sfeature="status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px;";
    msgFrm.showModelessDialog("javascript:alert(/""+msg+"/");window.close();","",sfeature);
    setTimeout("msgFrm.location.reload();",1000);
    }catch(e)
    {
     alert(msg);
    }
 } 

 

  //暂停函数
 function pause(numberMillis)
  {
  var dialogScript =  'window.setTimeout(' +' function () { window.close(); }, ' + numberMillis + ');';
  var result = window.showModalDialog('javascript:document.writeln(' + '"<script>' + dialogScript + '<' + '/script>")');
 }

 

  //使滚动条滚动到最底部(div)

    <div
     style="width:100%;height:210;top:0px;left:0px;overflow-y:auto;overflow-x:auto;border: black 1px solid;"
     name="contentTb" id="contentTb" oncontextmenu="showoff();">
    <table name="listTable" width="100%" id="listTable" align="left" border=0 cellspacing="0" cellpadding="0" class='listTable'>
     <tr class="head_tr">
      <td class='head_Td' style='width:15px;align:center'><input type="checkbox" onclick="javasrcipt:checkAllObj(this);"></td>
      <td class='head_Td' nowrap><font size='2'>编收</font></td>
      <td class='head_Td' width="6%"><font size='2'>编号</font></td>
      <td class='head_Td' nowrap><font size='2'>文号</font></td>
      <td class='head_Td' nowrap><font size='2'>&nbsp;&nbsp;文档标题&nbsp;&nbsp;</font></td>
      <td class='head_Td' nowrap width='6%'><font size='2'>份数</font></td>
      <td class='head_Td' nowrap><font size='2'>&nbsp;信封号&nbsp;</font></td>
      <td class='head_Td' nowrap><font size='2'>&nbsp;&nbsp;发文单位&nbsp;&nbsp;</font></td>
      <td class='head_Td' width="8%"><font size='2'>制文日期</font></td>
      <td class='head_Td' nowrap width='7%'><font size='2'>密级</font></td>
     </tr>
    </table>
    </div>


  var divContent=document.getElementById("contentTb");
  divContent.scrollTop=divContent.scrollHeight;