jQuery mobile转换url地址及获取url中目录部分的方法
作者:goldensun 发布时间:2023-07-02 05:34:34
标签:jQuery,url
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>


猜你喜欢
- 论证完使用target=_blank并非绝对错误之后,分场景探讨如何减少新开窗口。自有意识注意这个问题,是看到蓝色经典Plod大叔在04年提
- 2008年的圣诞节LOGO依旧延续着2007年的圣诞老人、鹿车、红帽子、圣诞树、蜡烛等元素装点。当然,也少不了雪花,但在LOGO设计上,较0
- 问题近日在做一组声纹聚类时,使用了另一团队同学开发的声纹距离算法。该算法对外提供的是一组so包,需要使用方自己去使用。在python中调用纯
- 在进行excel文件读取的时候,我自己设置了部分直接从公式获取单元格的值但是用之前的读取方法进行读取的时候,返回值为空import osim
- 前言作为一个数据库,作为数据库中的一张表,随着用户的增多随着时间的推移,总有一天,数据量会大到一个难以处理的地步。这时仅仅一张表的数据就已经
- 要写出一个五子棋游戏,我们最先要解决的,就是如何下子,如何判断已经五子连珠,而不是如何绘制画面,因此我们先确定棋盘五子棋采用15*15的棋盘
- 官方文档https://developers.weixin.qq.com/miniprogram/dev/devtools/download
- 一、数据引擎简介在MySQL 5.1中,MySQL AB引入了新的插件式存储引擎体系结构,允许将存储引擎加载到正在运新的MySQL
- facebook的信息架构设计,是目前为止互联网上我见过的最合理的信息架构。每次培训,我基本都需要拿20分钟左右的时间来解析它,包括老的、新
- python提高图像质量概述调研了一些提高图像质量的方式深度学习方法,如微软的Bringing-Old-Photos-Back-to-Lif
- 什么是Inception ResnetV2Inception ResnetV2是Inception ResnetV1的一个加强版,两者的结构
- 下面我们以论坛排行榜举例说明:<% @ LANGUAGE="VBSCRIPT" %&
- 作为一个MySQL的系统管理员,你有责任维护你的MySQL数据库系统的数据安全性和完整性。本文主要主要介绍如何建立一个安全的MySQL系统,
- 首先说明,伪造访问来路不是什么光明正大的事情,目的就是为了欺骗服务器。原本以为给 XMLHTTP 对象增加一个 Referer 的heade
- 使用python完成超级基础的学生管理系统,供大家参考,具体内容如下说明:1、本学生管理系统非常非常简易,只有增,显,查,删,改功能,对于P
- 题记:早已听闻python爬虫框架的大名。近些天学习了下其中的Scrapy爬虫框架,将自己理解的跟大家分享。有表述不当之处,望大神们斧正。一
- 1.python版本与matlab版本的对应关系在MAC中安装了Anaconda3,其中自带的python版本为3.8,通过python版本
- 用matplotlib.pyplot画的图,显示和保存的图片周围都会有白边,可以去掉。为了显示的更清楚,给图片加了红色的框代码“` impo
- 1、获取指定时间函数:date_format() 转换# 获取前一天时间的最大值SELECT date_format(CURRE
- 从2004年开始,我开始进入雅虎的异常表现小组。我们是一个很小的队伍,专门针对雅虎的产品进行质量检测和改进,我作为一个后端工程师,现在却开始