個人常用的JavaScript記錄

來源:互聯網
上載者:User
/******  DWR設定為同步,在回呼函數中可以操作主函數變數,之後再設為非同步即可  ******/DWREngine.setAsync(false);/******  使用splice(索引位置,數量)方法移除數組中的元素  ******/options.splice(i,1);/******  擷取縱向捲軸已滾動高度,橫向捲軸類似  ******/function getScrollTop(){    var scrollTop=0;    if(document.documentElement&&document.documentElement.scrollTop)    {        scrollTop=document.documentElement.scrollTop;    }    else if(document.body)    {        scrollTop=document.body.scrollTop;    }    return scrollTop;}/******  Iframe高度自動適應 Begin  ******/function reinitIframe(_iframe){var iframe = document.getElementById(_iframe);try{var bHeight = iframe.contentWindow.document.body.scrollHeight;var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;var height = Math.max(bHeight, dHeight);iframe.height =  height;}catch (ex){}}<iframe id="frame_edit" name="_edit" src=""  scrolling="no" frameborder="0" onload="this.height=100" width="100%"></iframe><script type="text/javascript">  window.setInterval("reinitIframe('frame_edit')",200);</script>/******  Iframe高度自動適應 End  ******/
style.display相容IE和FF的寫法document.getElementById("test").style.display="block";//IEdocument.getElementById("test").style.display="table-row";//FF同時相容的寫法:document.getElementById("test").style.display=document.all?"block":"table-row";document.getElementById("test").style.display="";
/* 通過name擷取radio被選的值 */function getRadioValue(rname){  var es = document.getElementsByName(rname);  if(es&&es!=null){    for(var i=0;i<es.length;i++){      if(es[i].checked)        return es[i].value;    }  }  return null;}//正則,匹配<script></script>var regScript = new RegExp("<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>","gi");//正則,匹配<style></style>var regStyle = new RegExp("<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>","gi");//正則,匹配所有標籤,如:<p>var regLabel = new RegExp("<[^>]+>","gi");//正則,匹配空格、換行等var regSpace = new RegExp("[\\n|\\r|\\t| |&nbsp;]","gi");/* 將HTML轉成純文字(清除HTML標籤代碼) */function html2text(value){ if(value=="")  return value; value = value.replace(regScript,""); value = value.replace(regStyle,""); value = value.replace(regLabel,""); value = value.replace(regSpace,""); return value;}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.