jQuery mobile轉換url位址及取得url中目錄部分的方法_jquery
path.makeUrlAbsolute() 把相對URL轉化為絕對URL
jQuery.mobile.path.makeUrlAbsolute( relUrl, absUrl )
把相對URL轉化為絕對URL的方法。這個函數回傳一個字串,絕對URL。
relUrl:相對網址。類型:字串。
absUrl:絕對網址。類型:字串。
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>jQuery.mobile.path.makeUrlAbsolute demo</title> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css"> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <!-- The script below can be omitted --> <script src="/resources/turnOffPushState.js"></script> <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script> <style> #myResult{ border: 1px solid; border-color: #108040; padding: 10px; } </style> </head> <body> <div data-role="page"> <div data-role="content"> <p>The absoulte URL used is http://foo.com/a/b/c/test.html</p> <input type="button" value="file.html" id="button1" class="myButton" data-inline="true"> <input type="button" value="../../foo/file.html" id="button2" class="myButton" data-inline="true"> <input type="button" value="//foo.com/bar/file.html" id="button3" class="myButton" data-inline="true"> <input type="button" value="?a=1&b=2" id="button4" class="myButton" data-inline="true"> <input type="button" value="#bar" id="button5" class="myButton" data-inline="true"> <div id="myResult">The result will be displayed here</div> </div> </div> <script> $(document).ready(function() { $( ".myButton" ).on( "click", function() { var absUrl = $.mobile.path.makeUrlAbsolute( $( this ).attr( "value" ), "http://foo.com/a/b/c/test.html" ); $( "#myResult" ).html( absUrl ); }) }); </script> </body> </html>
path.get() 決定URL中的目錄部分
jQuery.mobile.path.get( url )
url:只有一個參數。類型:字串。
確定URL中的目錄部分的實用方法。如果URL沒有斜線,URL的一部分被認為是一個檔案。這個函數傳回一個給定的URL目錄部分。
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>jQuery.mobile.path.get demo</title> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css"> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <!-- The script below can be omitted --> <script src="/resources/turnOffPushState.js"></script> <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script> <style> #myResult{ border: 1px solid; border-color: #108040; padding: 10px; } </style> </head> <body> <div data-role="page"> <div data-role="content"> <input type="button" value="http://foo.com/a/file.html" id="button1" class="myButton" data-inline="true" /> <input type="button" value="http://foo.com/a/" id="button2" class="myButton" data-inline="true" /> <input type="button" value="http://foo.com/a" id="button3" class="myButton" data-inline="true" /> <input type="button" value="//foo.com/a/file.html" id="button4" class="myButton" data-inline="true" /> <input type="button" value="/a/file.html" id="button5" class="myButton" data-inline="true" /> <input type="button" value="file.html" id="button6" class="myButton" data-inline="true" /> <input type="button" value="/file.html" id="button7" class="myButton" data-inline="true" /> <input type="button" value="?a=1&b=2" id="button8" class="myButton" data-inline="true" /> <input type="button" value="#foo" id="button9" class="myButton" data-inline="true" /> <div id="myResult">The result will be displayed here</div> </div> </div> <script> $(document).ready(function() { $( ".myButton" ).on( "click", function() { var dirName = $.mobile.path.get( $( this ).attr( "value" ) ); $( "#myResult" ).html( String( dirName ) ); }) }); </script> </body> </html>

熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

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

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

報錯的原因NameResolutionError(self.host,self,e)frome是由urllib3函式庫中的例外類型,這個錯誤的原因是DNS解析失敗,也就是說,試圖解析的主機名稱或IP位址無法找到。這可能是由於輸入的URL位址不正確,或DNS伺服器暫時無法使用所導致的。如何解決解決此錯誤的方法可能有以下幾種:檢查輸入的URL地址是否正確,確保它是可訪問的確保DNS伺服器可用,您可以嘗試在命令行中使用"ping"命令來測試DNS伺服器是否可用嘗試使用IP位址而不是主機名稱來存取網站如果是在代理

jQuery引用方法詳解:快速上手指南jQuery是一個受歡迎的JavaScript庫,被廣泛用於網站開發中,它簡化了JavaScript編程,並為開發者提供了豐富的功能和特性。本文將詳細介紹jQuery的引用方法,並提供具體的程式碼範例,幫助讀者快速上手。引入jQuery首先,我們需要在HTML檔案中引入jQuery函式庫。可以透過CDN連結的方式引入,也可以下載

區別:1、定義不同,url是是統一資源定位符,而html是超文本標記語言;2、一個html中可以有很多個url,而一個url中只能存在一個html頁面;3、html指的是網頁,而url指的是網站位址。

jQuery中如何使用PUT請求方式?在jQuery中,發送PUT請求的方法與發送其他類型的請求類似,但需要注意一些細節和參數設定。 PUT請求通常用於更新資源,例如更新資料庫中的資料或更新伺服器上的檔案。以下是在jQuery中使用PUT請求方式的具體程式碼範例。首先,確保引入了jQuery庫文件,然後可以透過以下方式發送PUT請求:$.ajax({u

jQuery如何移除元素的height屬性?在前端開發中,經常會遇到需要操作元素的高度屬性的需求。有時候,我們可能需要動態改變元素的高度,而有時候又需要移除元素的高度屬性。本文將介紹如何使用jQuery來移除元素的高度屬性,並提供具體的程式碼範例。在使用jQuery操作高度屬性之前,我們首先需要了解CSS中的height屬性。 height屬性用於設定元素的高度

標題:jQuery小技巧:快速修改頁面所有a標籤的文字在網頁開發中,我們經常需要對頁面中的元素進行修改和操作。使用jQuery時,有時候需要一次修改頁面中所有a標籤的文字內容,這樣可以節省時間和精力。以下將介紹如何使用jQuery快速修改頁面所有a標籤的文本,同時給出具體的程式碼範例。首先,我們需要引入jQuery庫文件,確保在頁面中引入了以下程式碼:<

標題:使用jQuery修改所有a標籤的文字內容jQuery是一款受歡迎的JavaScript庫,被廣泛用於處理DOM操作。在網頁開發中,經常會遇到需要修改頁面上連結標籤(a標籤)的文字內容的需求。本文將介紹如何使用jQuery來實現這個目標,並提供具體的程式碼範例。首先,我們需要在頁面中引入jQuery庫。在HTML檔案中加入以下程式碼:

如何判斷jQuery元素是否具有特定屬性?在使用jQuery操作DOM元素時,常會遇到需要判斷元素是否具有某個特定屬性的情況。在這種情況下,我們可以藉助jQuery提供的方法來輕鬆實現這項功能。以下將介紹兩種常用的方法來判斷一個jQuery元素是否具有特定屬性,並附上具體的程式碼範例。方法一:使用attr()方法和typeof運算子//判斷元素是否具有特定屬
