这篇文章主要介绍了使用jquery mobile库监测绝对地址和相对地址的方法,分别是isabsoluteurl()和isrelativeurl()方法的使用,需要的朋友可以参考下
path.isAbsoluteUrl() 检测绝对网址
jQuery.mobile.path.isAbsoluteUrl(url)
如果一个URL是绝对的实用方法。如果URL是绝对的这个函数返回一个布尔值 true ,否则返回 false。
html>
<meta>
<meta>
<title>jQuery.mobile.path.isAbsoluteUrl demo</title>
<link>
<script></script>
<!-- The script below can be omitted -->
<script></script>
<script></script>
<style>
#myResult{
border: 1px solid;
border-color: #108040;
padding: 10px;
}
</style>
<p>
</p><p>
<input>
<input>
<input>
<input>
<input>
<input>
</p><p>The result will be displayed here</p>
<script>
$(document).ready(function() {
$( ".myButton" ).on( "click", function() {
var isAbs = $.mobile.path.isAbsoluteUrl( $( this ).attr( "value" ) );
$( "#myResult" ).html( String( isAbs ) );
})
});
</script>
path.isRelativeUrl() 检查相对网址
jQuery.mobile.path.isRelativeUrl( url )
如果URL是相对的网址,这个函数返回一个布尔值 true,否则返回 false。
jQuery 1.12.4是jQuery 1.x系列的最后一个正式稳定版本,由jQuery团队于2016年发布。该版本主要面向需要兼容旧版浏览器环境的网站和Web应用,尤其适用于仍需支持Internet Explorer 6、Internet Explorer 7、Internet Explorer 8等老旧浏览器的项目。
html>
<meta>
<meta>
<title>jQuery.mobile.path.isRelativeUrl demo</title>
<link>
<script></script>
<!-- The script below can be omitted -->
<script></script>
<script></script>
<style>
#myResult{
border: 1px solid;
border-color: #108040;
padding: 10px;
}
</style>
<p>
</p><p>
<input>
<input>
<input>
<input>
<input>
<input>
</p><p>The result will be displayed here</p>
<script>
$(document).ready(function() {
$( ".myButton" ).on( "click", function() {
var isRel = $.mobile.path.isRelativeUrl( $( this ).attr( "value" ) );
$( "#myResult" ).html( String( isRel ) );
})
});
</script>
以上就是使用jQuery mobile库检测url绝对地址和相对地址的方法的内容,更多相关内容请关注PHP中文网(www.php.cn)!










