這篇文章帶給大家的內容是關於js中如何操作BOM物件? js中操作BOM物件的方法,有一定的參考價值,有需要的朋友可以參考一下,希望對你有幫助。
三個核心物件:
window:
[window].alert 只存在提示訊息 alert(message)
[window].prompt 允許使用者手動輸入 var obj=prompt(message)
[window].confirm 幫助使用者做判斷 當使用者點選確定的時候 回傳true,
點選取消的時候 返回false
open(url) 開啟指定的url位址
close() 關閉目前的標籤頁
confirm.html
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>confirm弹层</title> <script> function del(){ var flag = confirm('您确定要删除吗?'); if(flag){ alert("拜拜"); } else{ alert("我们还嫩能够继续。"); } } function toBaidu(){ open('https://www.baidu.com'); } </script></head><body> <!--删除按钮--> <!--<buttun onclick="javascript:confirm('您确定要删除吗?')">删除</buttun>--> <buttun onclick="del()">删除</buttun> <buttun onclick="toBaidu()">百度</buttun> <a href="history.html">去history页面</a> <button onclick="javascript:history.forward()">前进</button> </body> </html>
success.html
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>欢迎页</title> <script> function closeThis(){ close('./success.html'); } </script></head><body> <img src="/static/imghwm/default1.png" data-src="./img/gaoyuanyuan.png" class="lazy" / alt="js中如何操作BOM物件? js中操作BOM物件的方法" > 欢迎您! <button onclick="closeThis()">关闭</button> </body> </html>
setTimeout(function(){},毫秒) 指定时间延迟操作 只操作一次 var i=setInterval(function(){},毫秒) 指定时间延迟操作 操作多次(每隔一段时间操作一次) clearInterval(i) 清空定时特效 onload 事件:等待页面上的所有元素加载完毕
timing.html
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>定时函数</title> <script> function print(){ setTimeout( function(){ alert("我叫jhz"); },5000 ); } print(); </script> </head><body> <input name="btn" type="button" value="定时" onclick="print();" /> </body> </html>
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>定时函数</title> <script> window.onload=function(){ //保证页面上的元素加载完毕后 var btn=document.getElementsByTagName('button'); alert(btn); // 元素中的文本 innerText alert(btn.innerText); } </script> </head><body> <button id="btn">点击获取验证码</button></body></html>
history.html
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>history对象</title></head><body> <!--<button onclick="javascript:history.forward()">前进</button>--> <button onclick="javascript:history.back()">后退</button> </body> </html>
history:window
#
history:back() 回退===>go(-1)
forward() 前進 ===> go(1)
go(index) 即可前進 又可後退
#:這裡的前進後退與瀏覽器上的前進後退按鈕是一樣的效果。
當我們從一個網頁上造訪一個連結後可以後退回網頁,然後在網頁上可以再次前進到剛才跳轉的連結頁面。 (如同連續的上一個步驟和下一步似的)
location: window
host:主机地址+端口号 hostname:主机名 port:端口号 protocol:协议 href:发送请求到指定URL reload() 刷新当前页面 replace(url) 替换 以新的页面替换当前页面
location.html
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>location</title> <script> function toBaidu(){ //get请求 location.href="http://www.baidu.com"; Math Date } </script></head><body> <button onclick="javascript:alert(location.host)">查看主机地址</button> <button onclick="javascript:alert(location.hostname)">查看主机名</button> <button onclick="javascript:alert(location.port)">查看端口</button> <button onclick="javascript:alert(location.protocol)">查看协议</button> <button onclick="javascript:alert(location.href)">查看href</button> <button onclick="toBaidu()">去百度</button> <button onclick="javascript:location.reload()">刷新</button> <!--get请求--> <button onclick="javascript:location.replace('http://www.baidu.com')">replace百度</button></body></html>
—文件物件XML
#
document.getXXX()
var obj=document.getElementById(“id屬性值”) 根據頁面元素的id取得元素物件回傳的是單一節點物件
—————————–傳回的都是節點集合———— ————-
document.getElementsByName(“name屬性值”)根據頁面元素的name屬性取得元素物件
document.getElementsByClassName("class属性值") document.getElementsByTagName("节点名称")
javascript的內建物件的函數
**Math对象:** Math.ceil(number)向上取整 Math.floor(number) 向下取整 Math.round(number)四舍五入 Math.random() 生成0~1的随机数 **Date日期对象:** getDate = function() {}; // 获取当前日期(天) } getDay = function() {}; //一周中的第几天 } getMonth = function() {};// 一年中的第几月 } getFullYear = function() {};// 返回年份 4位数 } getHours = function() {}; //一天的第几个小时 } getMilliseconds = function() {}; //获取毫秒 当前分钟 } getMinutes = function() {};//分钟 当前小时 } getSeconds = function() {}; //秒 当前分钟 } getTime = function() {}; //时间 1970年1月1日 到现在的毫秒数
#date. html
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>date</title> <script> window.onload=function(){ var date = new Date(); alert(date.getDate());//获取当前日期(天) alert(date.getDay());//一周中的第几天 alert(date.getMonth());//一年中的第几月 0-7(cong0开始) alert(date.getFullYear());// 返回年份 4位数 alert(date.getHours());//一天的第几个小时 alert(date.getMilliseconds());//获取毫秒 当前分钟 alert(date.getMinutes ());//分钟 当前小时 alert(date.getSeconds ());//秒 当前分钟 alert(date.getTime());//时间 1970年1月1日 到现在的毫秒数 document.write("结束。"); } </script></head><body></body></html>
相關推薦:
以上是js中如何操作BOM物件? js中操作BOM物件的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

JavaScript的最新趨勢包括TypeScript的崛起、現代框架和庫的流行以及WebAssembly的應用。未來前景涵蓋更強大的類型系統、服務器端JavaScript的發展、人工智能和機器學習的擴展以及物聯網和邊緣計算的潛力。

JavaScript是現代Web開發的基石,它的主要功能包括事件驅動編程、動態內容生成和異步編程。 1)事件驅動編程允許網頁根據用戶操作動態變化。 2)動態內容生成使得頁面內容可以根據條件調整。 3)異步編程確保用戶界面不被阻塞。 JavaScript廣泛應用於網頁交互、單頁面應用和服務器端開發,極大地提升了用戶體驗和跨平台開發的靈活性。

Python更适合数据科学和机器学习,JavaScript更适合前端和全栈开发。1.Python以简洁语法和丰富库生态著称,适用于数据分析和Web开发。2.JavaScript是前端开发核心,Node.js支持服务器端编程,适用于全栈开发。

JavaScript不需要安裝,因為它已內置於現代瀏覽器中。你只需文本編輯器和瀏覽器即可開始使用。 1)在瀏覽器環境中,通過標籤嵌入HTML文件中運行。 2)在Node.js環境中,下載並安裝Node.js後,通過命令行運行JavaScript文件。

如何在Quartz中提前發送任務通知在使用Quartz定時器進行任務調度時,任務的執行時間是由cron表達式設定的。現�...

在JavaScript中如何獲取原型鏈上函數的參數在JavaScript編程中,理解和操作原型鏈上的函數參數是常見且重要的任�...

在微信小程序web-view中使用Vue.js動態style位移失效的原因分析在使用Vue.js...

在Tampermonkey中如何對多個鏈接進行並發GET請求並依次判斷返回結果?在Tampermonkey腳本中,我們經常需要對多個鏈...


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Dreamweaver CS6
視覺化網頁開發工具

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

禪工作室 13.0.1
強大的PHP整合開發環境

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境