搜尋
首頁Technical ResourcesJavaScript:void 0
JavaScript:void 0

JavaScript:void 0

可以使用return false、event.preventDefault()或空的href屬性值來取代JavaScript:void(0)。詳細介紹:1、return false,這種方法不會回傳undefined,並且可以被螢幕閱讀器正確解讀;2、event.preventDefault(),可以在點擊連結時呼叫event.preventDefault(),因此連結不會導航到新頁;3、空的href屬性值, 3. 使用空的href屬

232
8

JavaScript:void 0

javascript void:0是什麼

javascript void:0是什麼

javascript:void(0)是用來執行JavaScript程式碼的偽協議,常用於在不離開目前頁面的情況下執行一些操作,例如彈出警告框或執行其他JavaScript函數。作用是阻止瀏覽器預設的超連結行為,或防止頁面刷新 。詳細介紹:javascript:void(0)只是一個佔位符,本身不會執行任何實際的操作。

Aug 31, 2023 am 10:06 AM

JavaScript:void 0報錯怎麼解決

JavaScript:void 0報錯怎麼解決

JavaScript:void 0報錯可以透過修改程式碼邏輯、使用正確的連結或按鈕屬性、檢查程式碼語法錯誤、使用事件監聽器或使用其他方法來解決這個問題。詳細介紹:1、修改程式碼邏輯,可以使用return false;2、使用正確的連結或按鈕屬性,使用href="#"或onclick="return false;";3、檢查程式碼語法錯誤等等。

Aug 31, 2023 am 10:12 AM

JavaScript 地理定位:建立位置感知應用程式

JavaScript 地理定位:建立位置感知應用程式

在當今的數位時代,位置感知應用程式變得越來越流行。無論是基於地圖的服務、天氣應用程式還是食品配送平台,存取用戶的位置都可以大大增強用戶體驗。 JavaScript提供了強大的地理定位API,允許開發人員將基於位置的功能無縫整合到Web應用程式中。在本文中,我們將探索JavaScriptGeolocationAPI並了解如何建立位置感知應用程式。開始使用首先,讓我們來了解GeolocationAPI的基本概念。 API提供了一種檢索使用者設備地理位置的方法。它使用各種來源(例如GPS、Wi-Fi和I

Aug 30, 2023 pm 10:49 PM

如何在 JavaScript 中為 URL 新增參數?

如何在 JavaScript 中為 URL 新增參數?

在本文中,您將了解如何在JavaScript中為URL新增參數。在url中加入參數有兩種方法:append()方法和set()方法。 append()方法用於專門為url添加鍵值對。 set()方法將值加到特定鍵。如果該密鑰不存在,則會建立一個新密鑰。如果存在多個鍵,則更新其中一個鍵的值,並刪除其他鍵。範例1讓我們看看這個範例中的append()方法letinputUrl=newURL('https://urlExample.com?key1=value1');letinputParams=newU

Aug 30, 2023 pm 09:33 PM

JavaScript 程式求矩形的面積和周長

JavaScript 程式求矩形的面積和周長

我們正在編寫一個JavaScript程式來計算矩形的面積和周長。程式會提示使用者輸入矩形的寬度和長度,然後我們將使用這些值來計算面積和周長。我們將持續使用這些公式:面積=寬度*長度和周長=2*(寬度+長度)來找到所需的測量值。方法在JavaScript中尋找矩形的面積和周長的方法可以如下完成-使用變數定義矩形的長度和寬度。透過將矩形的長度和寬度相乘來計算面積。透過將矩形的兩倍長度和兩倍寬度相加來計算週長。顯示面積和周長的結果。將結果儲存在變數中,並在需要時傳回值。根據需要對不同的長度和寬度組

Aug 30, 2023 pm 02:05 PM

JavaScript中的source RegExp屬性的作用是什麼?

JavaScript中的source RegExp屬性的作用是什麼?

JavaScript中的來源RegExp屬性是RegExp物件的唯讀字串屬性。它包含RegExp模式的文字。此文字不包括正規表示式文字中使用的分隔斜杠,也不包括“g”、“i”和“m”屬性。範例您可以嘗試執行以下程式碼來了解如何在JavaScript中實作來源RegExp屬性-     JavaScriptRegExpsourcePrope</p><span class="Articlelist_txts_time">Aug 29, 2023 pm 01:21 PM</span></div></div><hr /><div class="Articlelist_txts"><a href="https://m.php.cn/zh-tw/faq/599480.html" title="如何在 JavaScript 中將數字轉換為陣列?" class="Articlelist_txtsimg"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/465/014/169328671359874.jpg?x-oss-process=image/resize,m_fill,h_135,w_240" class="lazy" alt="如何在 JavaScript 中將數字轉換為陣列?" /></a><div class="Articlelist_txts_info"><h3><a href="https://m.php.cn/zh-tw/faq/599480.html" title="如何在 JavaScript 中將數字轉換為陣列?" class="Articlelist_txts_title">如何在 JavaScript 中將數字轉換為陣列?</a></h3><p class="Articlelist_txts_p">在JavaScript中,有許多內建方法可以將數字轉換為陣列。最簡單的一種是split()方法。我們也可以使用map()、reduce()或form()方法來執行任務。本文討論了一些最受歡迎的將數字轉換為數組的方法,並提供了何時以及如何應用每種技術的範例。現在的問題是,為什麼需要將數字轉換為陣列?那麼原因可能是將電話號碼拆分為單獨的數字或將日期分解為其組成部分(解析日期),或者在對單獨的數字執行數學運算時它可能很有用。方法一:透過split()方法現在,我們來看看split()方法。它是一個有用的</p><span class="Articlelist_txts_time">Aug 29, 2023 pm 01:25 PM</span></div></div><hr /><div class="Articlelist_txts"><a href="https://m.php.cn/zh-tw/faq/599560.html" title="在 JavaScript 中按屬性從物件陣列中提取唯一對象" class="Articlelist_txtsimg"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/164/169329439656956.jpg?x-oss-process=image/resize,m_fill,h_135,w_240" class="lazy" alt="在 JavaScript 中按屬性從物件陣列中提取唯一對象" /></a><div class="Articlelist_txts_info"><h3><a href="https://m.php.cn/zh-tw/faq/599560.html" title="在 JavaScript 中按屬性從物件陣列中提取唯一對象" class="Articlelist_txts_title">在 JavaScript 中按屬性從物件陣列中提取唯一對象</a></h3><p class="Articlelist_txts_p">在本教程中,我們將學習按屬性從物件陣列中提取唯一物件。有時,我們需要根據特定屬性從物件陣列中過濾物件。例如,我們有一個id作為標識物件的鍵。因此,我們需要確保數組僅包含具有單一id的單一物件。如果兩個或多個物件包含相同的主鍵值,就會導致物件唯一標識的問題。在這裡,我們將學習根據特定屬性從陣列中過濾所有唯一物件的不同方法。使用地圖和for循環在JavaScript中,Map可以儲存唯一的鍵值對。此外,我們可以使用Map的鍵以O(1)的時間複雜度從Map中取得任何值。因此,我們將迭代物件數組並將鍵值</p><span class="Articlelist_txts_time">Aug 29, 2023 pm 03:33 PM</span></div></div><hr /></div><div class="AI_ToolDetails_main4sR"><div class="phpgenera_Details_mainR4"><div class="phpmain1_4R_readrank"><div class="phpmain1_4R_readrank_top"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" src="/static/imghwm/hotarticle2.png" alt="" /><h2>熱門文章</h2></div><div class="phpgenera_Details_mainR4_bottom"><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/600249.html" title="JavaScript:void 0報錯怎麼解決" class="phpgenera_Details_mainR4_bottom_title">JavaScript:void 0報錯怎麼解決</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>1 年前</span><span>Byzbt</span></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/600246.html" title="javascript void:0是什麼" class="phpgenera_Details_mainR4_bottom_title">javascript void:0是什麼</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>1 年前</span><span>Byzbt</span></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/600154.html" title="JavaScript 地理定位:建立位置感知應用程式" class="phpgenera_Details_mainR4_bottom_title">JavaScript 地理定位:建立位置感知應用程式</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>1 年前</span><span>ByPHPz</span></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/600125.html" title="如何在 JavaScript 中為 URL 新增參數?" class="phpgenera_Details_mainR4_bottom_title">如何在 JavaScript 中為 URL 新增參數?</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>1 年前</span><span>ByWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB</span></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/599925.html" title="JavaScript 程式求矩形的面積和周長" class="phpgenera_Details_mainR4_bottom_title">JavaScript 程式求矩形的面積和周長</a><div class="phpgenera_Details_mainR4_bottoms_info"><span>1 年前</span><span>By王林</span></div></div></div><div class="phpgenera_Details_mainR3_more"><a href="https://m.php.cn/zh-tw/article.html">顯示更多</a></div></div></div><div class="phpgenera_Details_mainR3"><div class="phpmain1_4R_readrank"><div class="phpmain1_4R_readrank_top"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" src="/static/imghwm/hottools2.png" alt="" /><h2>熱工具</h2></div><div class="phpgenera_Details_mainR3_bottom"><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/ai/kits-ai" title="Kits AI" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173417754263702.jpg?x-oss-process=image/resize,m_fill,h_45,w_45" class="lazy" alt="Kits AI" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/ai/kits-ai" title="Kits AI" class="phpmain_tab2_mids_title"><h3>Kits AI</h3></a><p>用人工智慧藝術家的聲音改變你的聲音。創建並訓練您自己的人工智慧語音模型。</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/ai/soundraw-ai-music-generator" title="SOUNDRAW - AI Music Generator" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173417756684210.jpeg?x-oss-process=image/resize,m_fill,h_45,w_45" class="lazy" alt="SOUNDRAW - AI Music Generator" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/ai/soundraw-ai-music-generator" title="SOUNDRAW - AI Music Generator" class="phpmain_tab2_mids_title"><h3>SOUNDRAW - AI Music Generator</h3></a><p>使用 SOUNDRAW 的 AI 音樂產生器輕鬆為影片、電影等創作音樂。</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/ai/web-chatgptai" title="Web ChatGPT.ai" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/ai_manual/001/246/273/173399378227633.jpg?x-oss-process=image/resize,m_fill,h_45,w_45" class="lazy" alt="Web ChatGPT.ai" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/ai/web-chatgptai" title="Web ChatGPT.ai" class="phpmain_tab2_mids_title"><h3>Web ChatGPT.ai</h3></a><p>使用OpenAI聊天機器人免費的Chrome Extension,以進行有效的瀏覽。</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/ai/resume-yay" title="Resume Yay" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/ai_manual/001/246/273/174597651711009.jpg?x-oss-process=image/resize,m_fill,h_45,w_45" class="lazy" alt="Resume Yay" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/ai/resume-yay" title="Resume Yay" class="phpmain_tab2_mids_title"><h3>Resume Yay</h3></a><p>真正免費的AI簡歷構建器</p></div></div><div class="phpmain_tab2_mids_top"><a href="https://m.php.cn/zh-tw/ai/bestcoloringpages" title="bestcoloringpages" class="phpmain_tab2_mids_top_img"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/ai_manual/001/246/273/174597649148886.jpg?x-oss-process=image/resize,m_fill,h_45,w_45" class="lazy" alt="bestcoloringpages" /></a><div class="phpmain_tab2_mids_info"><a href="https://m.php.cn/zh-tw/ai/bestcoloringpages" title="bestcoloringpages" class="phpmain_tab2_mids_title"><h3>bestcoloringpages</h3></a><p>所有年齡和場合的免費可打印的AI著色頁。</p></div></div></div><div class="phpgenera_Details_mainR3_more"><a href="https://m.php.cn/zh-tw/ai">顯示更多</a></div></div></div><div class="phpgenera_Details_mainR4"><div class="phpmain1_4R_readrank"><div class="phpmain1_4R_readrank_top"><img onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" onerror="this.onerror=''; this.src='/static/imghwm/default1.png'" src="/static/imghwm/hotarticle2.png" alt="" /><h2>熱門話題</h2></div><div class="phpgenera_Details_mainR4_bottom"><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/winkawaksrom" title="winkawaksrom" class="phpgenera_Details_mainR4_bottom_title">winkawaksrom</a><div class="phpgenera_Details_mainR4_bottoms_info"><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/eyess.png" alt="" /><span>208</span></div><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/tiezi.png" alt="" /><span>3</span></div></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/jxbcxwtzmjj" title="解析包時出現問題怎麼解決" class="phpgenera_Details_mainR4_bottom_title">解析包時出現問題怎麼解決</a><div class="phpgenera_Details_mainR4_bottoms_info"><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/eyess.png" alt="" /><span>1115</span></div><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/tiezi.png" alt="" /><span>5</span></div></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/ynxfpcfa" title="有哪些防爬蟲的方法" class="phpgenera_Details_mainR4_bottom_title">有哪些防爬蟲的方法</a><div class="phpgenera_Details_mainR4_bottoms_info"><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/eyess.png" alt="" /><span>262</span></div><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/tiezi.png" alt="" /><span>8</span></div></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/javajyfynx" title="java就業方向有哪些" class="phpgenera_Details_mainR4_bottom_title">java就業方向有哪些</a><div class="phpgenera_Details_mainR4_bottoms_info"><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/eyess.png" alt="" /><span>82</span></div><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/tiezi.png" alt="" /><span>5</span></div></div></div><div class="phpgenera_Details_mainR4_bottoms"><a href="https://m.php.cn/zh-tw/faq/insertbefore" title="insertbefore和before的差別" class="phpgenera_Details_mainR4_bottom_title">insertbefore和before的差別</a><div class="phpgenera_Details_mainR4_bottoms_info"><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/eyess.png" alt="" /><span>100</span></div><div class="phpgenera_Details_mainR4_bottoms_infos"><img src="/static/imghwm/tiezi.png" alt="" /><span>5</span></div></div></div></div><div class="phpgenera_Details_mainR3_more"><a href="https://m.php.cn/zh-tw/faq/zt">顯示更多</a></div></div></div></div></main><footer><div class="footer"><div class="footertop"><img src="/static/imghwm/logo.png" alt=""><p>公益線上PHP培訓,幫助PHP學習者快速成長!</p></div><div class="footermid"><a href="https://m.php.cn/zh-tw/about/us.html">關於我們</a><a href="https://m.php.cn/zh-tw/about/disclaimer.html">免責聲明</a><a href="https://m.php.cn/zh-tw/update/article_0_1.html">Sitemap</a></div><div class="footerbottom"><p> © php.cn All rights reserved </p></div></div></footer><script>isLogin = "0";</script><!-- Matomo --><script> var _paq = window._paq = window._paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="https://tongji.php.cn/"; _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '9']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); </script><!-- End Matomo Code --><script> // 通用函数,用于显示或隐藏元素 function toggleElementsDisplay(className, show) { const elements = document.getElementsByClassName(className); for (let i = 0; i < elements.length; i++) { elements[i].style.display = show ? "block" : "none"; } } // 绑定事件监听器 function bindEventListeners() { const toggleDisplay = (className, show, eventId) => { document.getElementById(eventId).addEventListener("click", (event) => { event.preventDefault(); toggleElementsDisplay(className, show); }); }; toggleDisplay("m_editormain12main", true, "fixed_tab_img"); toggleDisplay("m_editormain12main", false, "fixed_tab_topi"); toggleDisplay("m_editormain12main", false, "fixed_tab_close"); // 控制 m_menu 的显示和隐藏 toggleDisplay("m_menu", true, "lan1sp"); toggleDisplay("m_menu", false, "m_editormain12main_topi_sp"); // 控制 m_menu_lang 的显示和隐藏 toggleDisplay("m_menu_lang", true, "lan1"); toggleDisplay("m_menu_lang", false, "m_editormain12main_topi_lan"); } // 在页面加载完成后绑定事件监听器 window.onload = bindEventListeners; layui.use(function () { var util = layui.util; util.fixbar({ on: { mouseenter: function (type) { layer.tips(type, this, { tips: 4, fixed: true, }); }, mouseleave: function (type) { layer.closeAll("tips"); }, }, }); }); // 获取关闭按钮 const closeButton = document.querySelector(".phpgenera_Details_mainR1_close"); // 获取容器元素 const container = document.querySelector(".phpgenera_Details_mainR1"); // 添加点击事件监听器 closeButton.addEventListener("click", (event) => { event.preventDefault(); // 阻止默认的<a>点击行为 container.style.display = "none"; // 隐藏容器 }); document.addEventListener("DOMContentLoaded", () => { // 动态获取所有滚动链接及隐藏目标元素 const links = [{ linkId: "fixed_tab_a1", targetId: "Topic_Details_mainL2_R_title1", hideElementId: "fixed_tab_titlelist", // 要隐藏的元素 ID }, { linkId: "fixed_tab_a2", targetId: "Topic_Details_mainL2_R_title2", hideElementId: "fixed_tab_titlelist", // 要隐藏的元素 ID }, { linkId: "fixed_tab_a3", targetId: "Topic_Details_mainL2_R_title3", hideElementId: "fixed_tab_titlelist", // 要隐藏的元素 ID }, ]; links.forEach(({ linkId, targetId, hideElementId }) => { const linkElement = document.getElementById(linkId); const targetElement = document.getElementById(targetId); const hideElement = document.getElementById(hideElementId); if (linkElement && targetElement) { linkElement.addEventListener("click", (e) => { e.preventDefault(); // 阻止默认行为 // 隐藏指定元素 if (hideElement) { hideElement.style.display = "none"; } // 平滑滚动到目标元素 targetElement.scrollIntoView({ behavior: "smooth" }); }); } else { console.warn( `Link, target, or hide element not found: ${linkId}, ${targetId}, ${hideElementId}` ); } }); }); </script></body></html>