1.BOM學習

來源:互聯網
上載者:User

標籤:

1.bom.html

<html><head><title>bom示範</title><script type="text/javascript" src="js/bom.js"></script></head><body><div id = ‘d1‘>第一個div</div><div id = ‘d2‘>第二個div</div><a href="javascript:test();">測試</a></br><a href="javascript:testTimeout();">測試setTimeout</a></br><a href="javascript:testSetInterval();">測試setInterval</a></br><a href="javascript:stopInterval();">停止Interval</a></br><a href="javascript:alert(document.links.length);">多少個link?</a></br><a href="javascript:alert(document.links[0]);">第一個link的地址</a></br><a href="javascript:changeHtml();">改變第一個div的內容為“基本上為主”</a></br></body></html>

  

2.child.html

<html><head><title>子視窗</title><script type="text/javascript" src="js/bom.js"></script></head><body><a href="javascript:alert(window.opener.msg);">子視窗訪問父視窗的變數</a></body></html>

  

3.bom.js

//alert(window);//alert(window.document);//alert(window.document.links);//alert(window.document.anchors);//alert(window.document.forms);//alert(window.document.location);function test(){//惡搞/*while(1 > 0){window.moveTo(Math.random()*1000, Math.random()*100);//window.moveBy(400, 600);}*///alert(window.screenX);//alert(window.self);//window.open(‘child.html‘, ‘topFrame‘);var kti = 99888;alert(window.kti);}window.msg = ‘父視窗變數‘;//測試setTimeoutfunction sayHello(){alert(‘hello!‘);//return function(){alert(‘hello!‘)};}function testTimeout(){window.setTimeout(sayHello, 2000);//window.setTimeout(sayHello(), 2000);}//測試setIntervalvar t;function testSetInterval(){t = window.setInterval(sayHello, 1000);}function stopInterval(){window.clearInterval(t);}//改變html內容function changeHtml(){var k = document.getElementById(‘d1‘);alert(k);k.innerHTML = ‘基本上為主‘;}

  

1.BOM學習

聯繫我們

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