使用jQuery mobile庫檢測url絕對地址和相對地址的方法
更新時間:2015年12月04日 14:52:36 投稿:goldensun
這篇文章主要介紹了使用jQuery mobile庫監(jiān)測絕對地址和相對地址的方法,分別是isAbsoluteUrl()和isRelativeUrl()方法的使用,需要的朋友可以參考下
path.isAbsoluteUrl() 檢測絕對網(wǎng)址
jQuery.mobile.path.isAbsoluteUrl(url)
如果一個URL是絕對的實用方法。如果URL是絕對的這個函數(shù)返回一個布爾值 true ,否則返回 false。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery.mobile.path.isAbsoluteUrl demo</title>
<link rel="stylesheet" >
<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/file.html" id="button2" class="myButton" data-inline="true" />
<input type="button" value="/a/file.html" id="button3" class="myButton" data-inline="true" />
<input type="button" value="file.html" id="button4" class="myButton" data-inline="true" />
<input type="button" value="?a=1&b=2" id="button5" class="myButton" data-inline="true" />
<input type="button" value="#foo" id="button6" 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 isAbs = $.mobile.path.isAbsoluteUrl( $( this ).attr( "value" ) );
$( "#myResult" ).html( String( isAbs ) );
})
});
</script>
</body>
</html>
path.isRelativeUrl() 檢查相對網(wǎng)址
jQuery.mobile.path.isRelativeUrl( url )
如果URL是相對的網(wǎng)址,這個函數(shù)返回一個布爾值 true,否則返回 false。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery.mobile.path.isRelativeUrl demo</title>
<link rel="stylesheet" >
<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/file.html" id="button2" class="myButton" data-inline="true" />
<input type="button" value="/a/file.html" id="button3" class="myButton" data-inline="true" />
<input type="button" value="file.html" id="button4" class="myButton" data-inline="true" />
<input type="button" value="?a=1&b=2" id="button5" class="myButton" data-inline="true" />
<input type="button" value="#foo" id="button6" 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 isRel = $.mobile.path.isRelativeUrl( $( this ).attr( "value" ) );
$( "#myResult" ).html( String( isRel ) );
})
});
</script>
</body>
</html>
您可能感興趣的文章:
- jQuery Mobile操作HTML5的常用函數(shù)總結(jié)
- jQuery Mobile 和 Kendo UI 的比較
- jQuery Mobile頁面返回不需要重新get
- 詳解jQuery Mobile自定義標(biāo)簽
- jQuery mobile 移動web(4)
- jquerymobile checkbox及時刷新才能獲取其準(zhǔn)確值
- jQuery Mobile的loading對話框顯示/隱藏方法分享
- JqueryMobile動態(tài)生成listView并實現(xiàn)刷新的兩種方法
- 使用jquery mobile做幻燈播放效果實現(xiàn)步驟
- jQuery Mobile 導(dǎo)航欄代碼
- jQueryMobile之Helloworld與頁面切換的方法
- jQuery Mobile框架中的表單組件基礎(chǔ)使用教程
相關(guān)文章
jQuery中select與datalist制作下拉菜單時的區(qū)別淺析
一般我們通常使用select制作下拉菜單,但是H5之后,datalist也可以充當(dāng)select的角色,而且兩者還有一點小的不同。具體區(qū)別詳解小編通過本文給簡單介紹下2016-12-12
jQuery實現(xiàn)手機(jī)號碼輸入提示功能實例
這篇文章主要介紹了jQuery實現(xiàn)手機(jī)號碼輸入提示功能,實例分析了jQuery針對手機(jī)號碼的判斷與提示相關(guān)技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04
跟著JQuery API學(xué)Jquery 之二 屬性
在選擇器的API學(xué)習(xí)中,走馬觀花的把選擇器過了一遍,但是選擇歸選擇,選擇出來了沒干什么事,也沒有什么用嘛2010-04-04
jQuery動態(tài)添加 input type=file的實現(xiàn)代碼
有時候需要在頁面上允許用戶上傳多個文件,個數(shù)由用戶自己決定,個數(shù)多了也可以刪除,使用jQuery可以很簡單的實現(xiàn)這個功能2012-06-06

