一些基本的Javascript指令碼

來源:互聯網
上載者:User
1、無提示關閉視窗
<input type="button" onClick="window.opener = '';window.close();" value="IE6最簡單的無提示關閉視窗" >

2、防止被人iframe
if (top.location != self.location)
{
  top.location.href="http://www.34do.net";
}

3、判斷一個對象存在不存在
document.all("a")==null(不存在)

4、彈出子視窗
window.open ('default.asp', 'newwindow', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')

5、開啟模態視窗
window.showModalDialog('default.asp',window,'help: No; resizable: No; status: No;scrollbars:No;center: Yes;dialogWidth:width;dialogHeight:height;')

6、彈出的子視窗重新整理父視窗
window.parent.location.reload();

7、模態視窗重新整理父視窗
window.parent.dialogArguments.document.execCommand('Refresh');

8、一個js檔案包含另外一個js檔案
document.write('<script src="/b_trade/public/new/public.js"><\/script>');

9、讓文字豎著寫
<td style="Writing-mode:tb-rl;">佛羅倫</td>

10、iframe引用自己
window.parent.document.getElementById("iframe_dg")
這樣在iframe檔案裡就可以操作它自己,比如:window.parent.document.getElementById("iframe_dg").height=200

11、根據內容自動調整iframe高度
function autoSetiframeSize()
{
  var obj=self.parent.parent.document.all[self.name];
  if(obj!=null)
  {
    self.parent.parent.document.all[self.name].style.pixelHeight=self.document.body.scrollHeight+5;
  }
}
必須定義iframe的name屬性
<iframe id="iframe1" name="iframe1" align="center" frameborder="0" width="100%" height="250" scrolling="no" src="a.asp"></iframe>
將a.asp的<body>修改為:
<body onload="autoSetiframeSize()">

12、為儲存格添加漸層色效果(ie支援,firefox不支援)
.bg3
{
  FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr=#842B00, EndColorStr=#FFFFFF);
}

13、定時執行任務
規定一項任務在一定時間內執行:delayID=setTimeout(vCode, iMilliSeconds),在需要的時候,可以強制停止該任務:clearTimeout(delayID)

14、自動選中複製
<span onmouseover="var obj=document.body.createTextRange();obj.moveToElementText(this);obj.select();obj.execCommand('Copy')" onclick="var obj=document.body.createTextRange();obj.moveToElementText(this);obj.select();obj.execCommand('Copy')" >選中我並複製我</span>

15、產生隨機數
VB的Rnd函數產生的隨機數範圍為0-1。假如要從(min,max)這個範圍內隨機抽取一個數,具體公式如下: 隨機數 = (max - min) * Rnd() + min,min和max可以是任意整數,只是min<max。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.